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.
* 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>
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>
Comment (by yoyoma):
[https://github.com/django/django/pull/4193 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/24391#comment:3>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* severity: Normal => Release blocker
--
Ticket URL: <https://code.djangoproject.com/ticket/24391#comment:4>
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>
* 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>
* 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>
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>