[Django] #24497: Form datetime inconsistent handling

35 views
Skip to first unread message

Django

unread,
Mar 17, 2015, 8:01:34 AM3/17/15
to django-...@googlegroups.com
#24497: Form datetime inconsistent handling
-------------------------------+--------------------------
Reporter: riklaunim | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.7
Severity: Normal | Keywords: microseconds
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------
I've stumbled upon an yet another inconsistency in Django forms with
microseconds handling.

I have a model with DateTime field set with timezone.now(). In a form this
date is passed as hidden so that before save it can be verified that the
content didn't changed during moderation. The problem is that
timezone.now() sets microseconds, while datetime returned in form_valid is
without microseconds and thus can't be used for direct lookup on that
model field (and that what hurts).

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

Django

unread,
Mar 17, 2015, 7:56:57 PM3/17/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
------------------------------+------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7
Severity: Normal | Resolution:
Keywords: microseconds | 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):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

I guess
[https://github.com/django/django/blob/53d11c6821b7b347e0eeefb96168cc1861715a6b/django/forms/forms.py#L618-L622
this is the offending code].

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

Django

unread,
Mar 20, 2015, 12:54:09 PM3/20/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
------------------------------+------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7

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

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

Comment (by claudep):

It might be a use case for the `supports_microseconds` widget property
(which needs documentation, by the way).

Could you try to subclass `HiddenInput`, set `supports_microseconds` class
attribute to True for your subclass, and then use that widget in your
form?

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

Django

unread,
Mar 22, 2015, 8:42:58 AM3/22/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
------------------------------+------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7

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

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

Comment (by bmispelon):

Documentation issue tracked in #24520.

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

Django

unread,
Mar 22, 2015, 12:40:13 PM3/22/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
------------------------------+------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7

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

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

* cc: jiguromusha7@… (added)


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

Django

unread,
Mar 23, 2015, 4:52:17 AM3/23/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
------------------------------+------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7

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

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

Comment (by riklaunim):

Replying to [comment:2 claudep]:


> It might be a use case for the `supports_microseconds` widget property
(which needs documentation, by the way).
>
> Could you try to subclass `HiddenInput`, set `supports_microseconds`
class attribute to True for your subclass, and then use that widget in
your form?

Depends what should be the default behavior for a ModelForm? Field in a
model should be tailored to a matching form field and it validation rules.
If Django must permanently modify DatetTimes for display and alike
purposes then it should be explicit and consistent with models. If form
field has supports_microseconds then maybe DateTimeField in a model should
also have such attribute so that setting timezone.now()/datetime.now()
etc. won't save with microseconds in the first place?

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

Django

unread,
Mar 23, 2015, 8:31:14 AM3/23/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
------------------------------+------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7

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

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

Comment (by wdmgsm):

It was suggested by bmispelon in this
[https://github.com/django/django/pull/4373 pull request] to add
{{{supports_microseconds}}} to the base {{{Widget}}} class so that all
derived widgets inherit it.

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

Django

unread,
Apr 17, 2015, 6:36:29 PM4/17/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
------------------------------+------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7

Severity: Normal | Resolution:
Keywords: microseconds | 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):

* has_patch: 0 => 1


Comment:

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

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

Django

unread,
Apr 22, 2015, 5:47:08 PM4/22/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
------------------------------+------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7

Severity: Normal | Resolution:
Keywords: microseconds | 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


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

Django

unread,
May 5, 2015, 8:49:52 PM5/5/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
-------------------------------------+-------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7
Severity: Normal | Resolution:
Keywords: microseconds | Triage Stage: Ready for
| checkin

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
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/24497#comment:9>

Django

unread,
May 6, 2015, 7:20:29 AM5/6/15
to django-...@googlegroups.com
#24497: Truncation of microseconds in DateTimeField leads to lookup trouble
-------------------------------------+-------------------------------------
Reporter: riklaunim | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: microseconds | Triage Stage: Ready for
| checkin
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: new => closed
* resolution: => fixed


Comment:

In [changeset:"4dcc6493418c78db07761180bf6265f5b2bbccbf" 4dcc649]:
{{{
#!CommitTicketReference repository=""
revision="4dcc6493418c78db07761180bf6265f5b2bbccbf"
Fixed #24497 -- Added Widget.supports_microseconds attribute
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24497#comment:10>

Reply all
Reply to author
Forward
0 new messages