[Django] #30626: InlineModelAdmin fails validation of an empty form when there are ForeignKey and DecimalField with default="0.00"

5 views
Skip to first unread message

Django

unread,
Jul 8, 2019, 3:42:44 AM7/8/19
to django-...@googlegroups.com
#30626: InlineModelAdmin fails validation of an empty form when there are
ForeignKey and DecimalField with default="0.00"
-----------------------------------------+------------------------
Reporter: dchaplinsky | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.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 |
-----------------------------------------+------------------------
I have following code for the model:

{{{
class PayrollItem(models.Model):
payroll = models.ForeignKey(
"Payroll",
verbose_name="Payroll",
on_delete=models.CASCADE,
related_name="items",
)
contract = models.ForeignKey(
"Contract",
verbose_name="Contract",
on_delete=models.CASCADE,
related_name="payments",
)
hours = models.DecimalField("Hours", decimal_places=2, default="0.00",
max_digits=7, blank=True)
current_rate = models.DecimalField(
"Hourly rate", decimal_places=2, default="0.00", max_digits=7,
blank=True
)

}}}


which is then added as an `InlineModelAdmin`:


{{{
class PayrollItemInline(admin.TabularInline):
extra = 1
model = PayrollItem
}}}


when I hit save parent object, Django raises validation error for foreign
key of an empty inline form like in attached file

If I exclude "hours", "current_rate" everything works as expected!

--
Ticket URL: <https://code.djangoproject.com/ticket/30626>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 8, 2019, 3:42:56 AM7/8/19
to django-...@googlegroups.com
#30626: InlineModelAdmin fails validation of an empty form when there are
ForeignKey and DecimalField with default="0.00"
-------------------------------+--------------------------------------

Reporter: dchaplinsky | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.2
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 dchaplinsky):

* Attachment "nac35ntlfg831.jpg" added.

Validation error

Django

unread,
Jul 8, 2019, 4:59:42 AM7/8/19
to django-...@googlegroups.com
#30626: InlineModelAdmin fails validation of an empty form when there are
ForeignKey and DecimalField with default="0.00".
-------------------------------+--------------------------------------
Reporter: dchaplinsky | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: invalid

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 felixxm):

* status: new => closed
* version: 2.2 => master
* resolution: => invalid


Comment:

Thanks for this report, however your models configuration allows for such
behavior. If a field has `blank=True` form validation will allow entry of
an empty value (see
[https://docs.djangoproject.com/en/2.2/ref/models/fields/#blank` blank
documentation]) and `default` will not be used because value (empty) is
provided (see
[https://docs.djangoproject.com/en/2.2/ref/models/fields/#default default
documentation]). In the same time you have `NOT NULL` constraint in a
database.

Closing per TicketClosingReasons/UseSupportChannels.

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

Django

unread,
Jul 8, 2019, 5:00:50 AM7/8/19
to django-...@googlegroups.com
#30626: InlineModelAdmin fails of an empty form when DecimalField has default and
blank=True.
-------------------------------+--------------------------------------
Reporter: dchaplinsky | Owner: nobody

Type: Bug | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/30626#comment:2>

Reply all
Reply to author
Forward
0 new messages