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

Migrate Visualizations API to FastAPI #18721

Merged
merged 20 commits into from
Sep 9, 2024

Conversation

arash77
Copy link
Collaborator

@arash77 arash77 commented Aug 19, 2024

  • Refactor the legacy Visualizations API logic so all the logic is contained in the VisualizationsService class
  • Create pydantic models for the responses and payloads
  • Create the FastAPI routes that will replace the old ones

related to #10889

How to test the changes?

(Select all options that apply)

  • 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.

@github-actions github-actions bot added this to the 24.2 milestone Aug 19, 2024
@arash77 arash77 added the kind/refactoring cleanup or refactoring of existing code, no functional changes label Aug 19, 2024
@arash77 arash77 marked this pull request as draft August 19, 2024 16:59
@arash77 arash77 marked this pull request as ready for review August 20, 2024 10:56
lib/galaxy/schema/visualization.py Outdated Show resolved Hide resolved
lib/galaxy/webapps/galaxy/api/visualizations.py Outdated Show resolved Hide resolved
lib/galaxy/webapps/galaxy/api/visualizations.py Outdated Show resolved Hide resolved
lib/galaxy_test/api/test_tags.py Show resolved Hide resolved
lib/galaxy/webapps/galaxy/services/visualizations.py Outdated Show resolved Hide resolved
lib/galaxy/webapps/galaxy/services/visualizations.py Outdated Show resolved Hide resolved
lib/galaxy/webapps/galaxy/services/visualizations.py Outdated Show resolved Hide resolved
lib/galaxy/webapps/galaxy/services/visualizations.py Outdated Show resolved Hide resolved
lib/galaxy/webapps/galaxy/services/visualizations.py Outdated Show resolved Hide resolved
Copy link
Contributor

@davelopez davelopez left a 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.

@davelopez davelopez merged commit f669bb3 into galaxyproject:dev Sep 9, 2024
54 of 56 checks passed


class VisualizationCreatePayload(Model):
type: Optional[SanitizedString] = Field(
Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Member

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.

Copy link
Collaborator Author

@arash77 arash77 Sep 9, 2024

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?

Copy link
Member

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(
Copy link
Member

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 ?

Copy link
Collaborator Author

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.

Copy link
Member

@mvdbeek mvdbeek Sep 9, 2024

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.

Copy link
Collaborator Author

@arash77 arash77 Sep 9, 2024

Choose a reason for hiding this comment

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

None, title="Import ID", description="The encoded database identifier of the Visualization to import."
),
trans: ProvidesUserContext = DependsOnTrans,
) -> VisualizationCreateResponse:
"""
POST /api/visualizations
Copy link
Member

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")
Copy link
Member

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))
Copy link
Member

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
Copy link
Member

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

Copy link
Collaborator Author

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?

Copy link
Member

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"
Copy link
Member

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)
Copy link
Member

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.

@mvdbeek
Copy link
Member

mvdbeek commented Sep 9, 2024

Sorry for the late review, feel free to request a review via wg-backend or in the chat.

@davelopez
Copy link
Contributor

davelopez commented Sep 9, 2024

Sorry, I should have requested a wg-backend review instead of just commenting on it 😓

@arash77 arash77 mentioned this pull request Sep 9, 2024
4 tasks
@mvdbeek
Copy link
Member

mvdbeek commented Sep 9, 2024

No worries, the procedure was fine. It's not like these are major issues, and this doesn't need more than one review either.

@arash77 arash77 deleted the FastAPI_Visualizations branch September 9, 2024 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/API area/testing/api area/testing kind/refactoring cleanup or refactoring of existing code, no functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants