prefect
prefect copied to clipboard
Blocks in Prefect 2 can hold data not matching their schema
Bug summary
from prefect.blocks.core import Block
from prefect.testing.utilities import prefect_test_harness
with prefect_test_harness():
class MyBlock(Block):
setting_1: str = "foo"
blk1 = MyBlock(setting_1 = "bar")
blk1.save("a-block")
# redefining the block with a new schema
class MyBlock(Block):
setting_2: float = 1
blk2 = MyBlock(setting_2=0.5)
blk2.save("a-block", overwrite=True)
blk3 = MyBlock.load("a-block")
print(blk3.setting_1) # old data still accessible
print(blk3.setting_2)
when running the above code to simulate an update of a blocks schema, I can still access the old data from the previous schema after "migration". This is quite unexpected.
our current workaround is to delete the old block entirely before creating the new one.
Version info (prefect version output)
Version: 2.18.3
API version: 0.8.4
Python version: 3.11.6
Git commit: c449aee8
Built: Thu, May 2, 2024 5:47 PM
OS/Arch: darwin/arm64
Profile: default
Server type: ephemeral
Server:
Database: sqlite
SQLite version: 3.43.2
Additional context
No response