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

Use DeclarativeBase as base class for SA models #17897

Closed
wants to merge 2 commits into from

Conversation

jdavcs
Copy link
Member

@jdavcs jdavcs commented Apr 3, 2024

Post-SA2.0 model fixes (cherry-picked from #17662):

  1. Use proper DeclarativeBase as base class, as per sqlalchemy documentation.

  2. mypy bug workaround no longer needed as we are no longer specifying a metaclass.

  3. Use FromClause as the correct type instead of Table

  4. Fix table/__table__/HasTable for models. HasTable was a hack to accommodate declarative mapping without changing thousands of lines that referred to the table attribute of model instances.

    The one type:ignore added to managers.datasets can be removed after we map DatasetInstance models declaratively.

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.

@jdavcs jdavcs added kind/refactoring cleanup or refactoring of existing code, no functional changes area/database Galaxy's database or data access layer labels Apr 3, 2024
@jdavcs jdavcs added this to the 24.1 milestone Apr 3, 2024
@jdavcs jdavcs marked this pull request as draft April 3, 2024 21:17
mypy bug workaround no longer needed as we are no longer specifying a metaclass
@jdavcs jdavcs marked this pull request as ready for review April 3, 2024 21:58
@jdavcs jdavcs marked this pull request as draft April 3, 2024 22:04
@jdavcs jdavcs marked this pull request as ready for review April 3, 2024 23:00
@jdavcs jdavcs requested a review from a team April 3, 2024 23:00
@jdavcs
Copy link
Member Author

jdavcs commented Apr 3, 2024

Test failure unrelated.

@@ -999,7 +999,7 @@ class ModelFilterParser(HasAModelManager):
# (as the model informs how the filter params are parsed)
# I have no great idea where this 'belongs', so it's here for now

model_class: Type[model._HasTable]
model_class: Type[Union[model.Base, model.DatasetInstance]]
Copy link
Member

Choose a reason for hiding this comment

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

DatasetInstance doesn't look right here. If you do need to be more precise consider parameterizing this with a generic ?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need a union here only because hda and ldda are not mapped declaratively. model_class is the type for all SA models. All models but these two are mapped declaratively, which gives them a metadata instance variable. The hda and ldda models also have a metadata variable, which is why they can't be mapped declaratively (they will be eventually). Now, all declaratively mapped models inherit from DeclarativeBase. So the closest way to describe the type of all our models is the union of DeclarativeBase and the 2 non-declaratively mapped models - which both subclass DatasetInstance. This is tighter than the previous implementation (_HasTable, before that _BaseModel) which relied on the parent having a table variable.

@jdavcs
Copy link
Member Author

jdavcs commented Apr 12, 2024

Already merged as part of #17662

@jdavcs jdavcs closed this Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/database Galaxy's database or data access layer kind/refactoring cleanup or refactoring of existing code, no functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants