From fba308382b183584786825252f74e8ba92eee8ee Mon Sep 17 00:00:00 2001 From: Pawel Nalezyty Date: Tue, 10 Dec 2024 15:02:55 +0100 Subject: [PATCH 1/4] Backporting flow deletion in Prefect Python client to Prefect 2.0 --- src/prefect/client/orchestration.py | 17 +++++++++++++++++ tests/client/test_prefect_client.py | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/prefect/client/orchestration.py b/src/prefect/client/orchestration.py index 9cb2abb48fd8..0c54b70405e3 100644 --- a/src/prefect/client/orchestration.py +++ b/src/prefect/client/orchestration.py @@ -491,6 +491,23 @@ async def read_flow(self, flow_id: UUID) -> Flow: """ response = await self._client.get(f"/flows/{flow_id}") return Flow.parse_obj(response.json()) + + async def delete_flow(self, flow_id: UUID) -> None: + """ + Delete a flow by UUID. + Args: + flow_id: ID of the flow to be deleted + Raises: + prefect.exceptions.ObjectNotFound: If request returns 404 + httpx.RequestError: If requests fails + """ + try: + await self._client.delete(f"/flows/{flow_id}") + except httpx.HTTPStatusError as e: + if e.response.status_code == status.HTTP_404_NOT_FOUND: + raise prefect.exceptions.ObjectNotFound(http_exc=e) from e + else: + raise async def read_flows( self, diff --git a/tests/client/test_prefect_client.py b/tests/client/test_prefect_client.py index b48bd04cf1cc..06d3ca56b8eb 100644 --- a/tests/client/test_prefect_client.py +++ b/tests/client/test_prefect_client.py @@ -567,6 +567,19 @@ def foo(): assert lookup.name == foo.name +async def test_create_then_delete_flow(prefect_client): + @flow + def foo(): + pass + + flow_id = await prefect_client.create_flow(foo) + assert isinstance(flow_id, UUID) + + await prefect_client.delete_flow(flow_id) + with pytest.raises(prefect.exceptions.PrefectHTTPStatusError, match="404"): + await prefect_client.read_flow(flow_id) + + async def test_create_then_read_deployment( prefect_client, infrastructure_document_id, storage_document_id ): From dd173fa6cec388a4fe6ed4c188751add6da9a235 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Tue, 10 Dec 2024 08:43:49 -0600 Subject: [PATCH 2/4] tiny commit to make CI run --- .github/workflows/python-tests.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-tests.yaml b/.github/workflows/python-tests.yaml index f993c7b2c30c..629339a609f1 100644 --- a/.github/workflows/python-tests.yaml +++ b/.github/workflows/python-tests.yaml @@ -9,8 +9,8 @@ on: pull_request: paths: - .github/workflows/python-tests.yaml - - "src/prefect/**/*.py" - - "tests/**/*.py" + - src/prefect/**/*.py + - tests/**/*.py - requirements.txt - requirements-client.txt - requirements-dev.txt @@ -21,8 +21,8 @@ on: - 2.x paths: - .github/workflows/python-tests.yaml - - "src/prefect/**/*.py" - - "tests/**/*.py" + - src/prefect/**/*.py + - tests/**/*.py - requirements.txt - requirements-client.txt - requirements-dev.txt From 002937a6ed1562785f5d5e5d3b59513d4c3b922e Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Tue, 10 Dec 2024 10:00:55 -0600 Subject: [PATCH 3/4] run pre-commits --- src/prefect/client/orchestration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prefect/client/orchestration.py b/src/prefect/client/orchestration.py index 0c54b70405e3..9abfc5a91c3e 100644 --- a/src/prefect/client/orchestration.py +++ b/src/prefect/client/orchestration.py @@ -491,7 +491,7 @@ async def read_flow(self, flow_id: UUID) -> Flow: """ response = await self._client.get(f"/flows/{flow_id}") return Flow.parse_obj(response.json()) - + async def delete_flow(self, flow_id: UUID) -> None: """ Delete a flow by UUID. From ccd915f95c0c8c08d8208390c309b92b80e961e7 Mon Sep 17 00:00:00 2001 From: Pawel Nalezyty Date: Wed, 11 Dec 2024 11:24:36 +0100 Subject: [PATCH 4/4] Revert changes to the github actions file --- .github/workflows/python-tests.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-tests.yaml b/.github/workflows/python-tests.yaml index 629339a609f1..f993c7b2c30c 100644 --- a/.github/workflows/python-tests.yaml +++ b/.github/workflows/python-tests.yaml @@ -9,8 +9,8 @@ on: pull_request: paths: - .github/workflows/python-tests.yaml - - src/prefect/**/*.py - - tests/**/*.py + - "src/prefect/**/*.py" + - "tests/**/*.py" - requirements.txt - requirements-client.txt - requirements-dev.txt @@ -21,8 +21,8 @@ on: - 2.x paths: - .github/workflows/python-tests.yaml - - src/prefect/**/*.py - - tests/**/*.py + - "src/prefect/**/*.py" + - "tests/**/*.py" - requirements.txt - requirements-client.txt - requirements-dev.txt