Repository navigation
Render decimals as numbers in the OpenAPI YAML schema - #10112
Open
LindseyZ1205 wants to merge 1 commit into
Open
LindseyZ1205 wants to merge 1 commit into
LindseyZ1205 wants to merge 1 commit into
Conversation
The `OpenAPIRenderer` dumped `Decimal` values, such as the limits of a
`MaxValueValidator(Decimal('500'))` on a `DecimalField`, as
`!!python/object/apply:decimal.Decimal` tags, which YAML loaders other
than PyYAML's unsafe one can't read. Render them as numbers, as the
`JSONEncoder` used by the `JSONOpenAPIRenderer` does.
auvipy
self-requested a review
November 19, 2026 06:03
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
manage.py generateschema(and theOpenAPIRenderer) writesDecimalvalues in the schema as Python-specific YAML tags. For example, a model field such asgives
which YAML loaders other than PyYAML's unsafe one can't read:
yaml.safe_load()fails with "could not determine a constructor for the tag 'tag:yaml.org,2002:python/object/apply:decimal.Decimal'". Since #9997, a modelDecimalFieldwith a decimaldefaultends up in the schema in the same way.This is the same problem as #8063 for
timedelta, which was fixed with a representer for the YAMLDumper. This adds one forDecimal, which renders the value as a number, as theJSONEncoderof theJSONOpenAPIRendererdoes (maximum: 500.0,minimum: 0.01).I added a
DecimalFieldwith these validators toExampleValidatedSerializer, and a YAML rendering test next to thetimedeltaone; the test fails without the change. The full test suite passes with Django 6.1.2 and Django main, and flake8, isort and codespell pass on the changed files.