[Django] #36673: DecimalField max_digits and decimal_places should be optional and more general

11 views
Skip to first unread message

Django

unread,
Oct 20, 2025, 1:00:20 PM (2 days ago) Oct 20
to django-...@googlegroups.com
#36673: DecimalField max_digits and decimal_places should be optional and more
general
----------------------------+-----------------------------------------
Reporter: Gavin Wahl | Type: Uncategorized
Status: new | Component: Uncategorized
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-----------------------------------------
In Postgres and the SQL standard, it is not necessary to define a
precision and scale for NUMERIC/DECIMAL fields. However, Django requires
that they be specified.

https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-
NUMERIC-DECIMAL

I would like to be able to create an unconstrained NUMERIC field with
`DecimalField()`, but Django gives the error:

{{{
(fields.E130) DecimalFields must define a 'decimal_places' attribute.
fields.E132) DecimalFields must define a 'max_digits' attribute.
}}}

Also, the precision needs to be allowed to be less than the scale.
`NUMERIC(1,2)` is a valid type that stores numbers of the form `-0.00,
-0.01,...0.08, 0.09` but Django says:

{{{
(fields.E134) 'max_digits' must be greater or equal to 'decimal_places'.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36673>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 20, 2025, 1:02:16 PM (2 days ago) Oct 20
to django-...@googlegroups.com
#36673: DecimalField max_digits and decimal_places should be optional and more
general
-------------------------------------+-------------------------------------
Reporter: Gavin Wahl | Owner: (none)
Type: Uncategorized | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Gavin Wahl):

* cc: Gavin Wahl (added)
* component: Uncategorized => Database layer (models, ORM)

--
Ticket URL: <https://code.djangoproject.com/ticket/36673#comment:1>

Django

unread,
Oct 20, 2025, 3:01:59 PM (2 days ago) Oct 20
to django-...@googlegroups.com
#36673: DecimalField max_digits and decimal_places should be optional and more
general
-------------------------------------+-------------------------------------
Reporter: Gavin Wahl | Owner: (none)
Type: New feature | Status: closed
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* resolution: => duplicate
* status: new => closed
* type: Uncategorized => New feature

Comment:

Duplicate of #24920.
--
Ticket URL: <https://code.djangoproject.com/ticket/36673#comment:2>

Django

unread,
Oct 20, 2025, 6:12:31 PM (2 days ago) Oct 20
to django-...@googlegroups.com
#36673: DecimalField max_digits and decimal_places should be optional and more
general
-------------------------------------+-------------------------------------
Reporter: Gavin Wahl | Owner: (none)
Type: New feature | Status: closed
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Gavin Wahl):

That's a bug in inspectdb, related to floating-point fields (approximate)
in Oracle--I don't understand how it's a duplicate of this. I just want to
remove the overly-aggressive validation when using DecimalField (exact).
--
Ticket URL: <https://code.djangoproject.com/ticket/36673#comment:3>

Django

unread,
Oct 20, 2025, 6:39:28 PM (2 days ago) Oct 20
to django-...@googlegroups.com
#36673: DecimalField max_digits and decimal_places should be optional and more
general
-------------------------------------+-------------------------------------
Reporter: Gavin Wahl | Owner: (none)
Type: New feature | Status: closed
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim Graham):

Introspection fails because Django doesn't have any way to represent
numeric with unlimited precision. That representation is what you've
requested.
--
Ticket URL: <https://code.djangoproject.com/ticket/36673#comment:4>

Django

unread,
Oct 20, 2025, 6:54:48 PM (2 days ago) Oct 20
to django-...@googlegroups.com
#36673: DecimalField max_digits and decimal_places should be optional and more
general
-------------------------------------+-------------------------------------
Reporter: Gavin Wahl | Owner: (none)
Type: New feature | Status: closed
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Gavin Wahl):

That ticket requests an "ImpreciseDecimalField" to represent floating-
point (approximate) fields. Django's DecimalField is used to represent
exact values.

The Oracle inspectdb bug from the mailing list and ticket look like a
floating-point Oracle field getting incorrectly introspected as a
DecimalField instead of FloatField (perhaps this was before FloatField
existed?). I can contribute a patch to fix the DecimalField validation; I
can't fix Oracle introspection.
--
Ticket URL: <https://code.djangoproject.com/ticket/36673#comment:5>

Django

unread,
Oct 20, 2025, 6:55:32 PM (2 days ago) Oct 20
to django-...@googlegroups.com
#36673: DecimalField max_digits and decimal_places should be optional and more
general
-------------------------------------+-------------------------------------
Reporter: Gavin Wahl | Owner: (none)
Type: New feature | Status: closed
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

We should comment on #24920 to denote that it's not only about
introspection but I agree with Tim's triage here it's better to focus work
in a single ticket and gain introspection support along the way
particularly because the other ticket is so old.
--
Ticket URL: <https://code.djangoproject.com/ticket/36673#comment:6>
Reply all
Reply to author
Forward
0 new messages