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

Allow schema migration of block documents during Block.save #8056

Merged
merged 17 commits into from Jan 5, 2023

Conversation

zzstoatzz
Copy link
Contributor

@zzstoatzz zzstoatzz commented Jan 4, 2023

Adds block_schema_id to the BlockDocumentUpdate action schema to ensure that block_schema_id is passed to PATCH /block_document/{id}. This is so we can update the block_schema associated with an existing block document (if previously saved with a different block schema) when a user calls BlockWithNewSchema.save with overwrite=True, avoiding the need to delete and recreate the block document.

Closes #8015

Example

from prefect.blocks.core import Block

class Foo(Block):
   _block_type_name = "foo"
   _block_type_slug = "foo"

   x: int

foo = Foo(x=1)

foo.save("foo-block")

class Foo_Alias(Block):
   _block_type_name = "foo"
   _block_type_slug = "foo"

   x: int
   y: int

foo_alias = Foo_Alias.load("foo-block", validate=False)

foo_alias.y = 2

foo_alias.save("foo-block", overwrite=True)

# the schema ID for `foo-block` stored in Orion is now the same as the one stored on `foo_alias`, as of `save` being called

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • This pull request includes tests or only affects documentation.
  • This pull request includes a label categorizing the change e.g. fix, feature, enhancement

@netlify
Copy link

netlify bot commented Jan 4, 2023

Deploy Preview for prefect-orion ready!

Name Link
🔨 Latest commit ca89ddb
🔍 Latest deploy log https://app.netlify.com/sites/prefect-orion/deploys/63b73a4c6fd56200098b179d
😎 Deploy Preview https://deploy-preview-8056--prefect-orion.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@zzstoatzz zzstoatzz added the enhancement An improvement of an existing feature label Jan 5, 2023
@zzstoatzz zzstoatzz self-assigned this Jan 5, 2023
@zzstoatzz zzstoatzz linked an issue Jan 5, 2023 that may be closed by this pull request
3 tasks
@zzstoatzz zzstoatzz marked this pull request as ready for review January 5, 2023 16:23
@zzstoatzz
Copy link
Contributor Author

zzstoatzz commented Jan 5, 2023

looks like I broke some tests related to updating nested block documents 🤔

investigating

EDIT:
I think I just need to update the tests in the api & models to pass a block schema ID when we're simulating BlockDocumentUpdate actions

EDIT AGAIN:
I did not need to change the models/api tests, I was just missing a check that a new block schema ID was actually passed

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.

LGTM!

@zzstoatzz zzstoatzz merged commit 1a5d233 into main Jan 5, 2023
@zzstoatzz zzstoatzz deleted the allow-block-schema-changes branch January 5, 2023 21:26
@zanieb zanieb mentioned this pull request Feb 3, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow a block document's associated block schema to be changed
2 participants