Marc Lipoff02/02/2023, 9:58 PM
Nate02/02/2023, 10:06 PM
Marc Lipoff02/02/2023, 10:07 PM
and then I usually run
_config_environment_block = JSON(value=_config_environment) _config_environment_block.save("config", overwrite=True)
prefect block register -f example.py
.... there exist 2 blocks... whereas I'd really want the first block deleted
Nate02/02/2023, 10:15 PM
command is meant to tell your orion server (cloud, or hosted) that the implementation of the
prefect block register ...
subclass has changed. So you'd only need to
if you had done something like added an attribute to
class JSON(Block): # existing attrs ... new_attr: str = "hi!"
method is all you need to save new block instances I'm not sure we'd want orion to inspect your code to see if blocks are being used, but it sounds like maybe a more flexible way to bulk-delete block instances would be useful?
Marc Lipoff02/02/2023, 10:17 PM
prefect block register...
Nate02/02/2023, 10:57 PM
list all the blocks defined in codedo you mean instances of a certain type of block (like
Marc Lipoff02/02/2023, 10:57 PM
Nate02/02/2023, 10:58 PM
from prefect.blocks.core import Block class AddBlock(Block): x: int = 1 y: int = 2 def add(self): return self.x + self.y class MultiplyBlock(Block): x: int = 1 y: int = 2 def multiply(self): return self.x * self.y a = AddBlock(x=42) m = MultiplyBlock(y=42)
i just threw this together but could be formalized if there was a desire to have some sort of dry run as a CLI cmd / util
import inspect from prefect.blocks.core import Block from prefect.utilities.importtools import load_script_as_module filename = "blocks.py" # file where some block instances are defined # load the file as a module module = load_script_as_module(filename) instances = [ obj for name, obj in inspect.getmembers(module) if not inspect.isclass(obj) and isinstance(obj, Block) ] print(instances) # yields [AddBlock(x=42, y=2), MultiplyBlock(x=1, y=42)]
Marc Lipoff02/06/2023, 7:27 PM