Use correct JSON schema dialect for param validation #15483
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #13560
Whilst this issue is already closed, the problem is not actually fixed in v3, see #13560 (comment)
Context
This issue occurs when trying to deploy a flow which uses a Pydantic model as a parameter. Specifically, JSON schema validation for this parameter fails if the model contains a field with a numeric
gt
orlt
constraint (or a type alias to that effect, e.g.pydantic.PositiveFloat
).Cause
On the client side,
prefect.deployments.runner.RunnerDeployment
callsprefect.utilities.callables.generate_parameter_schema
to generate a JSON schema for the flow parametersInternally, this calls
prefect._internal.pydantic.v2_schema.create_v2_schema
, which uses a subclass ofpydantic.json_schema.GenerateJsonSchema
for the actual schema generationCrucially, this class (and Pydantic in general since since v2.0) uses Draft 2020-12 as the default JSON Schema dialect.
When Prefect server receives the
POST /api/deployments/
request, FastAPI tries to construct and validate aprefect.server.schemas.actions.DeploymentCreate
model from the request bodyThe model validation method for
DeploymentCreate
validates the parameter OpenAPI schema usingprefect._internal.schemas.validators.validate_parameter_openapi_schema
Internally, this calls
jsonschema.Draft4Validator.check_schema
to do the actual validationObviously, this schema validation class uses the Draft 4 JSON Schema dialect.
As you can see in the JSON Schema docs,
exclusiveMinimum
andexclusiveMaximum
were boolean as of Draft 4 but have subsequently changed to numeric type.Proposed solution
Update the server-side validation to use
jsonschema.Draft202012Validator
Checklist
<link to issue>
"mint.json
.