[Django] #24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline formsets

35 views
Skip to first unread message

Django

unread,
Feb 22, 2015, 1:49:51 PM2/22/15
to django-...@googlegroups.com
#24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline
formsets
-------------------------------+--------------------
Reporter: yoyoma | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
When using {{{DateTimeField(default=timezone.now)}}}, inline model
formsets know to avoid validation when no fields are changed, even though
there is a value in that given {{{DateTimeField}}}. However, when using
another field ({{{UUIDField}}} in my case) I'm getting inline form
validation on otherwise empty forms, presumably due to the default UUID
being different than the one generated during POST.

This is at least related to #24377, but since this isn't constrained to
{{{primary_key=True}}} cases, it needs its own ticket. Could a general
solution to this render a specific solution to #24377 moot, or are they
two separate issues?

== Digression ==

How does this {{{if user changed the default datetime value: count the
form as having been changed}}} functionality work, btw? My understanding
of dynamic default values like this is that there would be no way for
Django to know whether the value has changed, unless the default value was
included in a hidden field, or set in cache or cookies on page load... I'd
love to document this, because if a user creates their own form field they
might want to build in this sort of functionality.

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

Django

unread,
Feb 22, 2015, 2:58:57 PM2/22/15
to django-...@googlegroups.com
#24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline
formsets
------------------------+-------------------------------------
Reporter: yoyoma | Owner: timgraham
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------+-------------------------------------
Changes (by timgraham):

* status: new => assigned
* needs_better_patch: => 0
* needs_tests: => 0
* owner: nobody => timgraham
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


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

Django

unread,
Feb 22, 2015, 3:26:58 PM2/22/15
to django-...@googlegroups.com
#24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline
formsets
------------------------+-------------------------------------
Reporter: yoyoma | Owner: timgraham
Type: Bug | Status: assigned
Component: Forms | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------+-------------------------------------

Comment (by timgraham):

The root cause is that the default is
[https://github.com/django/django/blob/b2f331dc68ec3c5a34285f7af9614e4178e9a371/django/forms/forms.py#L493
called twice] when rendering the field so the hidden initial value is
different from what appears in the input. I think this bug was hidden with
the common case of datetime defaults because microseconds are truncated so
usually the two values are equal, although it seems like it should trip
across a second boundary at some point.

Maybe we can evaluate the default on the form field, rather than the
widget. Backwards compatibility is the main concern.

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

Django

unread,
Feb 22, 2015, 10:15:44 PM2/22/15
to django-...@googlegroups.com
#24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline
formsets
------------------------+-------------------------------------
Reporter: yoyoma | Owner: timgraham
Type: Bug | Status: assigned
Component: Forms | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------+-------------------------------------

Comment (by yoyoma):

[https://github.com/django/django/pull/4193 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/24391#comment:3>

Django

unread,
Feb 23, 2015, 8:52:47 AM2/23/15
to django-...@googlegroups.com
#24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline
formsets
---------------------------------+-------------------------------------

Reporter: yoyoma | Owner: timgraham
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* severity: Normal => Release blocker


--
Ticket URL: <https://code.djangoproject.com/ticket/24391#comment:4>

Django

unread,
Feb 23, 2015, 6:21:17 PM2/23/15
to django-...@googlegroups.com
#24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline
formsets
---------------------------------+-------------------------------------
Reporter: yoyoma | Owner: timgraham
Type: Bug | Status: assigned
Component: Forms | Version: master

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------

Comment (by timgraham):

#11390 - If you use a callable as default value on a model field, it gets
called 3 times - is related and probably addressed at least partially by
this.

--
Ticket URL: <https://code.djangoproject.com/ticket/24391#comment:5>

Django

unread,
Feb 24, 2015, 12:41:50 PM2/24/15
to django-...@googlegroups.com
#24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline
formsets
---------------------------------+-------------------------------------
Reporter: yoyoma | Owner: timgraham
Type: Bug | Status: assigned
Component: Forms | Version: master

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0


Comment:

Updated [https://github.com/django/django/pull/4206 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/24391#comment:6>

Django

unread,
Feb 24, 2015, 8:05:19 PM2/24/15
to django-...@googlegroups.com
#24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline
formsets
---------------------------------+-------------------------------------
Reporter: yoyoma | Owner: timgraham
Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"65441bbdb02427655869c42791a0bc5a9c631292"]:
{{{
#!CommitTicketReference repository=""
revision="65441bbdb02427655869c42791a0bc5a9c631292"
Fixed #24391 -- Made BoundField.value() cache callable values.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24391#comment:7>

Django

unread,
Feb 24, 2015, 8:05:32 PM2/24/15
to django-...@googlegroups.com
#24391: UUIDField with default=uuid4 triggers validation on otherwise empty inline
formsets
---------------------------------+-------------------------------------
Reporter: yoyoma | Owner: timgraham
Type: Bug | Status: closed
Component: Forms | Version: master

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"278b6987943d0a610aadc767200651ec5d7d738e"]:
{{{
#!CommitTicketReference repository=""
revision="278b6987943d0a610aadc767200651ec5d7d738e"
[1.8.x] Fixed #24391 -- Made BoundField.value() cache callable values.

Backport of 65441bbdb02427655869c42791a0bc5a9c631292 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24391#comment:8>

Reply all
Reply to author
Forward
0 new messages