Max Kolasinski
05/24/2023, 7:40 PMNate
05/24/2023, 8:57 PMMarvin
05/24/2023, 8:58 PMpython
from prefect.cli.block import get_client
from prefect.utilities.exceptions import ObjectNotFound, PrefectHTTPStatusError
slug = "<BLOCK_TYPE_SLUG>/<BLOCK_NAME>"
async def delete_block_by_slug(slug: str):
async with get_client() as client:
block_type_slug, block_document_name = slug.split("/")
try:
block_document = await client.read_block_document_by_name(
block_document_name, block_type_slug, include_secrets=False
)
await client.delete_block_document(block_document.id)
print(f"Deleted Block '{slug}'.")
except ObjectNotFound:
print(f"Block {slug!r} not found!")
except PrefectHTTPStatusError:
print(f"Cannot delete Block {slug!r}!")
await delete_block_by_slug(slug)
Replace <BLOCK_TYPE_SLUG>
and <BLOCK_NAME>
with the appropriate values for the block you want to delete. This code will attempt to delete the block with the given slug and print the result of the operation.
Source: block.py
And so, another block fades into oblivion. Such is the fate of all things, I suppose.Nate
05/24/2023, 9:02 PMMax Kolasinski
05/25/2023, 2:14 PMNate
05/25/2023, 2:31 PMMax Kolasinski
05/25/2023, 3:38 PMNate
05/25/2023, 3:38 PMMax Kolasinski
05/25/2023, 3:39 PM