-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow blocks in deployment params #14741
Allow blocks in deployment params #14741
Conversation
CodSpeed Performance ReportMerging #14741 will improve performances by 22%Comparing Summary
Benchmarks breakdown
|
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.
a few code nit picks - also could you add a test for what this initialization looks like, and also a test for using a block type hint with a flow that validates its parameters?
Ultimately it'd be better (and easier to reason about) if the API could pass the block slug to the client for validation, but this might be an OK patch in the meantime as that will involve more changes.
I've also tagged @desertaxle for review here, as he might have more insight into this implementation and whether there are any edge cases we should consider.
I added block reference validation to check if it matches initialized block type. Not sure if both slug and type should be compared, or only one of them or should be validated differently. |
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.
Thanks for the PR @GalLadislav, this will be a super useful feature! Let me know if you have any questions about any of my requested changes!
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 looks pretty solid to me! I requested one additional test for nested block references, and will wait on @desertaxle's final review as well. Also note that you probably need to update with main
and run pre-commit hooks for tests to pass 👍
Thank you for taking the time to work on this @GalLadislav !!
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.
LGTM! Thanks for the awesome contribution @GalLadislav!
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.
Thanks again @GalLadislav for working with us on this and being so responsive to our feedback!!
Thank you @desertaxle @cicdw for your time and guidance. I am happy i could contribute. |
Context
Related #14393
I tried to "fix" Prefect's 3.0 inability to pass Blocks as deployments parameters. This feature is really important for me personally (and probably for others too). Since the related issue was closed as "not planned", i implemented something that could provide at least some functionality until it is properly addressed.
I would appreciate a feedback if this PR is useful and is worthwhile to polish it and add unittests etc. Thank you in advance for any guidance.
Implementation
Implementation is building on already existing UI features in FlowRunCreate for deployment runs that use passing
{"$ref": "__uuid__"}
as block reference. I have tracked to main issues which causes this feature to not work.Block
does not processes the $ref in init kwargs.Server validation API
To allow $ref for blocks, preprocessing schemas modify block definition to allow either block definition or block reference.
Added two $ref formats, one that supports deployment flow run create form and one that supports multiple reference types.
Block initialization
For Block class i added method
Block.load_from_ref
that process either block document ID or supported reference dictionary format and returns loaded block with data from references block document.Other changes:
Block._load_from_block_document
method to deal with duplicate code used both inBlock.load
andBlock.load_from_ref
.Block._get_block_document_by_id
Flow.validate_parameters
updated to transform any block reference in given parameters to corresponding block withBlock.load_from_ref
.Issues
Checklist
<link to issue>
.