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

Refactor db_injector decorator #16390

Merged
merged 1 commit into from
Dec 15, 2024

Conversation

mjpieters
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link

codspeed-hq bot commented Dec 14, 2024

CodSpeed Performance Report

Merging #16390 will not alter performance

Comparing mjpieters:refactor_db_injector (45fa127) with main (df9d64f)

Summary

✅ 3 untouched benchmarks

@mjpieters mjpieters force-pushed the refactor_db_injector branch from 50d3954 to aedde6a Compare December 14, 2024 02:07
Comment on lines 251 to 255
# 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.
Copy link
Member

@desertaxle desertaxle Dec 14, 2024

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@mjpieters mjpieters force-pushed the refactor_db_injector branch 3 times, most recently from ab3c8a3 to 5d6356d Compare December 14, 2024 15:52
@mjpieters mjpieters requested a review from desertaxle December 14, 2024 15:53
@mjpieters mjpieters force-pushed the refactor_db_injector branch from 5d6356d to dffdbf7 Compare December 14, 2024 16:43
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.
@mjpieters mjpieters force-pushed the refactor_db_injector branch from dffdbf7 to 45fa127 Compare December 14, 2024 16:46
Copy link
Member

@desertaxle desertaxle left a 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?

@desertaxle desertaxle merged commit b42d3a1 into PrefectHQ:main Dec 15, 2024
37 checks passed
@mjpieters mjpieters deleted the refactor_db_injector branch December 15, 2024 04:23
@mjpieters
Copy link
Contributor Author

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.

mjpieters added a commit to mjpieters/prefect that referenced this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants