Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[24.0] Restore histories API behavior for keys query parameter #17779

Conversation

davelopez
Copy link
Contributor

Fixes #17726 (comment) and addresses #17726 (comment)

as an example, when requesting /api/histories?keys=name:

Before these changes

[
  {
    "model_class": "History",
    "id": null,
    "user_id": null,
    "name": "Unnamed history"
  }
]

After these changes

[
  {
    "name": "Unnamed history"
  }
]

This PR adds a partial_model decorator discussed in the Pydantic community as a workaround to support partial (all fields optional) models until Python supports this concept natively.

The CustomHistoryView model now replaces HistoryMinimal by using this "partial_model" decorator and including any other fields the client might request. The "allow extra fields" configuration has been removed from the base model and now we need to be explicit about what the history response model can contain.

It also includes some refactorings/fixes around client model types since most components assumed the history objects contained all fields.

Finally, I increased the test coverage for using "view" and "keys" query parameters in histories.

How to test the changes?

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

@davelopez davelopez force-pushed the 24.0_restore_histories_API_behaviour_for_keys_query branch from 7630a9f to 95eedff Compare March 18, 2024 17:51
Comment on lines +137 to +143
export function isHistorySummary(history: AnyHistory): history is HistorySummary {
return !("user_id" in history);
}

export function isHistorySummaryExtended(history: AnyHistory): history is HistorySummaryExtended {
return "contents_active" in history && "user_id" in history;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about adding a constant field in the model that indicates what view we're dealing with ?
The pro is that we don't need helper to figure out the actual type, the con is that we're serializing more than strictly necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would simplify things yes, I like the idea, but I didn't consider it because it was changing the API response again 😆 but I can give it a try and see how we feel about it. Should I target this in a follow-up on dev for that change though? Or directly in this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's target dev and mention it at the backend meeting ? We do have a related precedent in model_class which is only used for a similar purpose. Yet another alternative is that we include the model-type in the response header, which doesn't alter the response in the body but that would at least be more explicit than "contents_active" in history && "user_id" in history, which feels like a contract we could easily break accidentally.

@mvdbeek
Copy link
Member

mvdbeek commented Mar 19, 2024

This is awesome, I like it a lot!

Supports both HDA and HDCA states.
@davelopez davelopez marked this pull request as ready for review March 19, 2024 14:36
@davelopez
Copy link
Contributor Author

This one should be ready to review, only the flaky Toolshed tests are failing now.

@mvdbeek mvdbeek merged commit 5714783 into galaxyproject:release_24.0 Mar 20, 2024
51 of 53 checks passed
@mvdbeek
Copy link
Member

mvdbeek commented Mar 20, 2024

Thank you @davelopez!

@davelopez davelopez deleted the 24.0_restore_histories_API_behaviour_for_keys_query branch March 20, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants