Lutz Ostkamp
07/17/2025, 12:59 PMMarvin
07/17/2025, 12:59 PMMarvin
07/17/2025, 1:00 PMpython
from prefect.blocks.system import JSON
# Load the block
my_block = JSON.load("block-name")
# Override values before using
my_block.value = {"new": "value"}
2. Create a Copy with New Values
python
from prefect.blocks.system import JSON
# Load the block and modify it without affecting the stored version
original_block = JSON.load("block-name")
modified_block = JSON(
**original_block.dict() | {"value": {"new": "value"}}
)
The key points to remember are:
1. Modifications made to a block instance after loading it are temporary and only affect that instance
2. The original block stored in the Prefect server remains unchanged
3. You can modify any field that's defined on the block
Here's a more practical example using an S3 bucket block:
python
from prefect.blocks.system import Secret
from prefect.filesystems import S3
@flow
def my_flow():
# Load the block
s3_block = S3.load("my-s3-block")
# Override the bucket name for this specific flow run
s3_block.bucket_name = "different-bucket"
# Use the modified block
s3_block.write_path("my-file.txt", "some/path")
This approach is particularly useful when you need to:
- Test different configurations
- Temporarily modify block settings for specific flow runs
- Handle different environments or scenarios within the same flow
Remember that these modifications are runtime-only and won't persist back to the stored block configuration. If you need to permanently change the block's values, you should create and save a new block configuration instead.
Links:
- Prefect Blocks Concept Documentation
- Advanced Blocks Documentation