-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Migrate Visualizations API to FastAPI #18721
Conversation
…ta as json to Visualization api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you @arash77!
I'll leave it open for some time in case anyone else wants to add a comment.
|
||
|
||
class VisualizationCreatePayload(Model): | ||
type: Optional[SanitizedString] = Field( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably has a set value of things that can be filled in, we should document and restrict those values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find the specific set of values. Can you point me where to find them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess these are the plugin types loaded into VisualizationsRegistry. Might be a little tricky to load them up since you need the fully loaded plugins registry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, Should I leave it like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but make it a normal string. It must match the plugin type, no need to do sanitization there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for type
in VisualizationCreatePayload
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
title="Config", | ||
description="The config of the visualization.", | ||
) | ||
save: Optional[bool] = Field( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a visualization that is not saved ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just added this because it existed in the old API!
But yes that is useless to have such a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know ? Maybe that's used to preview a visualization ? But if so it would be broken since the None as the id won't validate against the response model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is hardcoded from the old code to True!
https://github.com/galaxyproject/galaxy/blob/release_24.1/lib/galaxy/webapps/galaxy/api/visualizations.py#L304
I will remove it.
None, title="Import ID", description="The encoded database identifier of the Visualization to import." | ||
), | ||
trans: ProvidesUserContext = DependsOnTrans, | ||
) -> VisualizationCreateResponse: | ||
""" | ||
POST /api/visualizations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dosctring ends up as documentation in the schema, we don't need to include stuff like POST /api/visualizations
there.
else: | ||
# must have a type (I've taken this to be the visualization name) | ||
if not payload.type: | ||
raise exceptions.RequestParameterMissingException("key/value 'type' is required") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't happen given the new enforced API signature, right ?
with transaction(session): | ||
session.commit() | ||
|
||
return VisualizationCreateResponse(id=str(visualization.id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're not committing the visusalization visualization.id is None, in which case the VisualizationCreateResponse is invalid.
try: | ||
visualization = trans.sa_session.get(Visualization, visualization_id) | ||
except TypeError: | ||
visualization = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's never going to be a type error, the try/except doesn't do anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should I just remove the try/except?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
# Error checking. | ||
title_err = slug_err = "" | ||
if not title: | ||
title_err = "visualization name is required" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case just don't make the title
optional in the function signature ? We want to validate this as much as possible via the pydantic models for the endpoints, which you're doing.
slug_builder = SlugBuilder() | ||
slug_builder.create_item_slug(trans.sa_session, visualization) | ||
if annotation: | ||
annotation = sanitize_html(annotation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should or need to do this, but also you're already doing this in the incoming pydantic model.
Sorry for the late review, feel free to request a review via wg-backend or in the chat. |
Sorry, I should have requested a wg-backend review instead of just commenting on it 😓 |
No worries, the procedure was fine. It's not like these are major issues, and this doesn't need more than one review either. |
Visualizations
API logic so all the logic is contained in theVisualizationsService
classrelated to #10889
How to test the changes?
(Select all options that apply)
License