-
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
Improve type hints in manager classes #18129
Improve type hints in manager classes #18129
Conversation
392da47
to
c22dfd8
Compare
c22dfd8
to
baf7fef
Compare
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.
Wonderful!
Feel free to ignore some of the type hint suggestions if they create more issues than they are worth.
lib/galaxy/model/__init__.py
Outdated
@@ -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) |
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 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.
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.
Hehe, I was looking for that, it would have saved me from changing all those unit tests 😆
baf7fef
to
7f9a46c
Compare
This means that when we list/filter/retrieve items from a given manager we get the correct return type, instead of `any`.
The model optionality on the sqlalchemy side seems weird.
Co-authored-by: David López <[email protected]>
This allows type lookups using TypedDict, which isn't possible with enum members.
81d7635
to
70aa9d7
Compare
Co-authored-by: David López <[email protected]>
The one failing test is unrelated. |
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 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: |
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'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, |
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 think what we want here is DatasetSourceType
🤔
DataItemSourceType, | |
DatasetSourceType, |
hda_manager.error_if_uploading(hda) | ||
hda_manager.error_unless_mutable(hda.history) |
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 wonder if one more dictionary called raise_delete_error_by_type
that will call these 2 methods for hda
s and just no-op for ldda
s will eliminate this duplication 🤔
This is so heavily conflicted now it probably doesn't make sense to keep around. |
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)
License