Skip to content

Commit

Permalink
a couple typing and error improvements (#15081)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz authored Aug 26, 2024
1 parent 24fb039 commit 178c6e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/prefect/client/orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,12 @@ async def read_deployment(
Returns:
a [Deployment model][prefect.client.schemas.objects.Deployment] representation of the deployment
"""
if not isinstance(deployment_id, UUID):
try:
deployment_id = UUID(deployment_id)
except ValueError:
raise ValueError(f"Invalid deployment ID: {deployment_id}")

try:
response = await self._client.get(f"/deployments/{deployment_id}")
except httpx.HTTPStatusError as e:
Expand Down
4 changes: 2 additions & 2 deletions src/prefect/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ async def to_deployment(
cron: Optional[Union[Iterable[str], str]] = None,
rrule: Optional[Union[Iterable[str], str]] = None,
paused: Optional[bool] = None,
schedules: Optional[List["FlexibleScheduleList"]] = None,
schedules: Optional["FlexibleScheduleList"] = None,
concurrency_limit: Optional[int] = None,
parameters: Optional[dict] = None,
triggers: Optional[List[Union[DeploymentTriggerTypes, TriggerTypes]]] = None,
Expand Down Expand Up @@ -730,7 +730,7 @@ def my_other_flow(name):
work_pool_name=work_pool_name,
work_queue_name=work_queue_name,
job_variables=job_variables,
)
) # type: ignore # TODO: remove sync_compatible
else:
return RunnerDeployment.from_flow(
self,
Expand Down
7 changes: 7 additions & 0 deletions tests/client/test_prefect_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,13 @@ def foo():
assert lookup.parameter_openapi_schema == {}


async def test_read_deployment_errors_on_invalid_uuid(prefect_client):
with pytest.raises(
ValueError, match="Invalid deployment ID: not-a-real-deployment"
):
await prefect_client.read_deployment("not-a-real-deployment")


async def test_update_deployment(prefect_client, storage_document_id):
@flow
def foo():
Expand Down

0 comments on commit 178c6e0

Please sign in to comment.