Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mdefeche opened this issue Dec 22, 2023 · 1 comment
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@mdefeche
Copy link

mdefeche commented Dec 22, 2023

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

tfranzel added a commit that referenced this issue Dec 26, 2023
this is to prevent accidental scientific notation and
thus introducing !!float yaml tag that NOBODY likes.
tfranzel added a commit that referenced this issue Dec 26, 2023
coerse Decimal to float format explicitly #1134
@tfranzel tfranzel added bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Dec 26, 2023
@mdefeche
Copy link
Author

mdefeche commented Jan 3, 2024

I confirm the fix is working as expected

        value:
          type: number
          format: double
          maximum: 1.0
          minimum: 0.0000001

Thank you for swiftly fixing this

@mdefeche mdefeche closed this as completed Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending
Projects
None yet
Development

No branches or pull requests

2 participants