#31841: DecimalField doesnt't respect max_digits when converting -------------------------------------+------------------------------------- Reporter: Thiago Bellini | Owner: nobody Ribeiro | Type: Bug | Status: closed Component: Database layer | Version: 3.0 (models, ORM) | Severity: Normal | Resolution: wontfix Keywords: | Triage Stage: | Unreviewed Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Thiago Bellini Ribeiro): Hi felixxm, I understand what you mean regarding the context but I don't think the the proposed solution to the issue there can solve this one here. The context itself can't define the number of decimal places, just the precision that is the number of digits in the float. So, there's no way to configure the context so it will respect DecimalField's max_digits. The example I gave above is a perfect example to that and something that happened to me some times in some of my project. Even if the field defined decimal_places of 6 and since it has 20 max_digits defined, the code would convert 0.2 to something that has 19 decimal places. That exact code and the test cases that I changed there would give errors if they were running really being set on a database with postgresql (don't know if other databases would produce errors as well). If the round doesn't work for everything maybe we can explore other solutions, but since the DecimalField allows for float conversion and used a context to make sure it respects max_digits, IMHO it should also respect decimal_places too, or else you end up with corner cases like that where you can't trust the float conversion ever. -- Ticket URL: <https://code.djangoproject.com/ticket/31841#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.10f21903fb20b5034fa4d0e611372e16%40djangoproject.com.