Hi All, We are using a script to programmatically...
# prefect-cloud
a
Hi All, We are using a script to programmatically delete unused blocks from our dev environment via the API using
prefect block delete...
. However, when trying to delete these blocks, we keep getting 409 Conflict error codes on those blocks. Strange, because the same blocks can be deleted just fine through the UI. Any ideas on how we could resolve this? Feeling like some kind of issue with how the API is handling block deletion...
1
n
hi @Ananya Mishra - can you share the script that you're using? and the output of
prefect version
if possible
a
it's a bit layered, but the gist is we collect all the block slugs to delete into an python dict like this
{'kubernetes-job/deployment-infra-16899', 's3/deployment-storage-16451', 'kubernetes-job/deployment-infra-16541', ...}
and then run
subprocess.run(f"prefect block delete {slug}", shell=True)
in python for each block
Copy code
root@421ed1fe04e5:~/.prefect# prefect version
Version:             2.7.12
API version:         0.8.4
Python version:      3.11.1
Git commit:          524c25cd
Built:               Mon, Feb 6, 2023 4:31 PM
OS/Arch:             linux/aarch64
Profile:             default
Server type:         cloud
n
is there a reason you're using the CLI? I would use the client for this
a
cool let me try that
n
cool! lmk if you need any more direction on that, you should just have to collect the block ids you need and pass them to that client method
a
is id different from the slug i posted above?
n
so I would use this to read the block document by
slug
(as you have above), grab the ID (a UUID) off each one with
block_document.id
and then pass that value into
delete_block_document
👀 1
Copy code
from prefect import get_client
from uuid import UUID

slugs = ["block-type/block-doc-slug", ...]

async with get_client() as client:
   for slug in slugs:
      type_slug, name_slug = slug.split('/')
      block_document = await client.read_block_document_by_slug(name_slug, type_slug)
      await client.delete_block_document(UUID(block_document.id))
should be something like this
a
hmm yeah that didn't really change anything. still getting
Copy code
httpx.HTTPStatusError: Client error '409 Conflict' for url '<https://api.prefect.cloud/api/accounts/b8194971-9f89-43fe-a099-69552528a88a/workspaces/e0b524be-50ed-4eca-b77b-d2a1b2ade39f/block_documents/5fd2e02b-160e-4cf4-a990-5754e5e6230a>'
i think we need to take a closer look at what is happening with those objects on the server side that could be leading to these 409s
is there some other process we don't see using them?
perhaps you can take a look at that exact object i sent and see what's up there...or if you can delete it programmatically from your end.
n
ah, are any of these blocks used by any of your deployments that exist?
i noticed your slugs were referring to storage and infra blocks, so if these were associated with an active deployment, this would be expected behavior - although we could probably improve the error message
a
i see. so then we need to make sure all associated deployments are deleted first?
n
yes
👀 1
a
also i guess it's good for yall to note this is permitted by your UI while the API seems to catch it?
🙏 1
n
hmm i will check on that