-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Refactor db_injector decorator #16390
Conversation
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 was in the process of cleaning up the database interface when I noticed that this decorator wasn't really useful in a method context but I really wanted it to be. Once this lands I'll be using it to clean up the db interface area.
CodSpeed Performance ReportMerging #16390 will not alter performanceComparing Summary
|
50d3954
to
aedde6a
Compare
# TODO: what would it take for PrefectBaseModel to list this type as | ||
# ignored, by default? This decorator is confined to the prefect.server | ||
# namespace and PrefectBaseModel needs to work in a client-only context, | ||
# so we rather not import across that boundary. |
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 are two PrefectBaseModel
implementations. One from prefect._internal.schemas.bases
and one from prefect.server.utilities.schemas.bases
. The latter is the one that should be used server-side and I think that we could ignore this type by default there without crossing the client/server boundary.
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.
That is very interesting and would indeed make this much easier to resolve. I have a circular import to resolve though. Tomorrow.
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.
Resolved by creating a base descriptor class in the same module. Any subclass of that base is automatically included in the ignored types, and can trivially be imported without dependency issues.
ab3c8a3
to
5d6356d
Compare
5d6356d
to
dffdbf7
Compare
The decorator now returns a custom descriptor object instead of a wrapper function. The descriptor can then keep the `self` and database interface objects separate without having to reverse the normal argument order.
dffdbf7
to
45fa127
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.
This is great! Thank you!
I'm less familiar with the descriptor protocol than I'd like to be. Do you know of any docs or guides that cover it particularly well?
The Python documentation has been improving on this front, the Descriptor Guide in the howto section is very comprehensive now. |
The decorator now returns a custom descriptor object instead of a wrapper function. The descriptor can then keep the
self
and database interface objects separate without having to reverse the normal argument order.