Skip to content

Decimals represented in scientific notation cannot be rendered in YAML rendered #1134

@mdefeche

Description

@mdefeche

Describe the bug
Renderer cannot represent numbers written in scientific notation.

To Reproduce
Use a validator using decimal.Decimal with a least 7 decimals. Starting at 7 decimals, numbers will get printed in scientific notation (eg. 1E-7)

class MyTestModel(models.Model):

    value= models.DecimalField(
        max_digits=9
        decimal_places=7,
        validators=[MinValueValidator(Decimal("0.0000001")), MaxValueValidator(Decimal("1.0"))],
    )

The resulting YAML will look like !!int '1E-7' and an error will be generated in Redoc view cannot resolve a node with !<tag:yaml.org,2002:int> explicit tag

Expected behavior
The value should be 0.0000001 in the yaml file.

It looks like the issue comes from the following method where the str method is used. Maybe a format would work value = '{:f}'.format(data)

Thank you in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfix confirmation pendingissue has been fixed and confirmation from issue reporter is pending

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions