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

Improve type hints in manager classes #18129

Closed

Conversation

mvdbeek
Copy link
Member

@mvdbeek mvdbeek commented May 13, 2024

Most of the return values of the central managers now have type annotations, which has already caught a couple of minor issues (4fdcb1b, 77af0f6 and c8d4f14)

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.

@mvdbeek mvdbeek added the kind/refactoring cleanup or refactoring of existing code, no functional changes label May 13, 2024
@github-actions github-actions bot added this to the 24.1 milestone May 13, 2024
@mvdbeek mvdbeek force-pushed the improve_type_hints_in_manager_classes branch 2 times, most recently from 392da47 to c22dfd8 Compare May 14, 2024 08:54
@mvdbeek mvdbeek force-pushed the improve_type_hints_in_manager_classes branch from c22dfd8 to baf7fef Compare May 14, 2024 09:25
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.

Wonderful!
Feel free to ignore some of the type hint suggestions if they create more issues than they are worth.

lib/galaxy/managers/datasets.py Show resolved Hide resolved
lib/galaxy/managers/users.py Outdated Show resolved Hide resolved
lib/galaxy/managers/users.py Outdated Show resolved Hide resolved
@@ -732,7 +732,7 @@ class User(Base, Dictifiable, RepresentById):
create_time: Mapped[datetime] = mapped_column(default=now, nullable=True)
update_time: Mapped[datetime] = mapped_column(default=now, onupdate=now, nullable=True)
email: Mapped[str] = mapped_column(TrimmedString(255), index=True)
username: Mapped[Optional[str]] = mapped_column(TrimmedString(255), index=True, unique=True)
username: Mapped[str] = mapped_column(TrimmedString(255), index=True, unique=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understood correctly the third bullet point in #17958, we need to add nullable=True to mapped_column to reflect the real table definition.

The same applies to the rest of the model attributes that changed to non-optional type hints here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hehe, I was looking for that, it would have saved me from changing all those unit tests 😆

@mvdbeek mvdbeek removed this from the 24.1 milestone May 14, 2024
@mvdbeek mvdbeek force-pushed the improve_type_hints_in_manager_classes branch from baf7fef to 7f9a46c Compare May 21, 2024 12:55
@mvdbeek mvdbeek force-pushed the improve_type_hints_in_manager_classes branch from 81d7635 to 70aa9d7 Compare May 23, 2024 15:20
Co-authored-by: David López <[email protected]>
@mvdbeek
Copy link
Member Author

mvdbeek commented May 24, 2024

The one failing test is unrelated.

@mvdbeek mvdbeek requested a review from a team May 24, 2024 06:54
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.

I love all these refactorings! thank you very much!

Just a couple of comments, one I think might be an ugly bug about archived (non-purged) histories 😞

raise exceptions.MessageException(f"User '{item.email}' has not been deleted, so they cannot be purged.")
private_role = self.app.security_agent.get_private_user_role(item)
# Delete History
for active_history in item.active_histories:
Copy link
Contributor

Choose a reason for hiding this comment

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

I've just noticed that this probably will not purge archived histories from the user... 😬 😞

description="Whether this dataset belongs to a history (HDA) or a library (LDDA).",
)
HdaLddaField = Annotated[
DataItemSourceType,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think what we want here is DatasetSourceType 🤔

Suggested change
DataItemSourceType,
DatasetSourceType,

Comment on lines +738 to +739
hda_manager.error_if_uploading(hda)
hda_manager.error_unless_mutable(hda.history)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if one more dictionary called raise_delete_error_by_type that will call these 2 methods for hdas and just no-op for lddas will eliminate this duplication 🤔

@mvdbeek
Copy link
Member Author

mvdbeek commented Nov 28, 2024

This is so heavily conflicted now it probably doesn't make sense to keep around.

@mvdbeek mvdbeek closed this Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/API area/database Galaxy's database or data access layer area/testing/integration area/testing area/tool-framework kind/refactoring cleanup or refactoring of existing code, no functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants