prefect
prefect copied to clipboard
Improve error message on non-compliant block document names
I didn't see an explicit constraint on block document names containing hyphenated-lowercase in the docs so when calling .save() on mySecret block, I passed name='my_api_key', which raised something like:
File ~/opt/miniconda3/envs/muhproject/lib/python3.10/site-packages/prefect/client.py:226, in PrefectResponse.raise_for_status(self)
224 return super().raise_for_status()
225 except HTTPStatusError as exc:
--> 226 raise PrefectHTTPStatusError.from_httpx_error(exc) from exc.__cause__
PrefectHTTPStatusError: Client error '422 Unprocessable Entity' for url 'https://api.prefect.cloud/api/accounts/xxx/workspaces/xxx/block_documents/'
Response: {'exception_message': 'Invalid request received.', 'exception_detail': [{'loc': ['body', 'name'], 'msg': 'name must only contain lowercase letters, numbers, and dashes', 'type': 'value_error'}, {'loc': ['body', '__root__'], 'msg': 'Names must be provided for block documents.', 'type': 'value_error'}], 'request_body': {'name': 'my_api_key', 'data': {'value': 'xxx'}, 'block_schema_id': 'xxx', 'block_type_id': 'xxx', 'is_anonymous': False}}
For more information check: https://httpstatuses.com/422
where the output ultimately contained the info I need to resolve the error, but still thought I'd raise it in case we want to improve it in clarity and/or brevity
@desertaxle pointed out that this format validation was taking place here:
https://github.com/PrefectHQ/prefect/blob/983ed7f3d604cdde7a045cb4f36b273337bd8a15/src/prefect/orion/schemas/actions.py#L24-L31