Code

Opened 2 years ago

Closed 2 years ago

#17165 closed Bug (duplicate)

SelectDateWidget does not work correctly with has_changed()

Reported by: rene@… Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords: SelectDateWidget changed has_changed changed_data
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

See http://groups.google.com/group/django-users/browse_thread/thread/45c2a4b6a2f0ba67

Attachments (2)

1.3.X.diff (1.8 KB) - added by rene_f 2 years ago.
Patch against the 1.3.X branch.
trunk.diff (1.9 KB) - added by rene_f 2 years ago.
Patch against trunk

Download all attachments as: .zip

Change History (16)

comment:1 Changed 2 years ago by rene_f

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to rene_f
  • Patch needs improvement unset
  • Status changed from new to assigned

Changed 2 years ago by rene_f

Patch against the 1.3.X branch.

comment:2 Changed 2 years ago by rene_f

  • Has patch set
  • Owner rene_f deleted
  • Status changed from assigned to new
  • Version changed from 1.3 to SVN

comment:3 Changed 2 years ago by rene_f

The problem is that Widget._has_changed compares a localized string representation of the date to a datetime.date object. The patch addresses the issue by overriding _has_changed in SelectDateWidget and passing the data value as a datetime.date object to Widget._has_changed.

comment:4 Changed 2 years ago by anonymous

  • Owner set to nobody

Changed 2 years ago by rene_f

Patch against trunk

comment:5 Changed 2 years ago by julien

  • Triage Stage changed from Unreviewed to Accepted

Thanks for the report. The patch looks good, I'm just about to push it. You'll note that I've just fleshed out the tests a bit to be sure it works if the field's show_hidden_initial is True. Cheers!

comment:6 Changed 2 years ago by julien

  • Resolution set to fixed
  • Status changed from new to closed

In [17071]:

Fixed #17165 -- Fixed SelectDateWidget._has_changed() to work correctly with a localized date format.

comment:7 Changed 2 years ago by julien

rene_f, my apologies for not mentioning you in the commit message. Thanks again for your contribution.

comment:8 Changed 2 years ago by rene_f

julien, no problem. Thanks for your quick reaction.

Will the fix also be applied to the 1.3.X branch? It might be nice to have it included in a possible 1.3.2 release. I attached a separate diff for 1.3.X (avoids datetime.strptime for Python 2.4 compatibility).

comment:9 Changed 2 years ago by julien

The policy is to only commit severe bug fixes to older branches; see: https://docs.djangoproject.com/en/dev/internals/release-process/#supported-versions
I don't think the severity of this bug qualifies, so you'll have to wait till the next release which should hopefully happen soon.

comment:10 Changed 2 years ago by fon.vosi@…

  • Patch needs improvement set

doesn't work for me
when SelectDateWidget is empty and i check "if 'fieldname' in self.changed_data" for some other field
django fires TypeError "must be string, not None" in django/forms/extras/widgets.py "data = datetime_safe.datetime.strptime(data, input_format).date()"

so, you should make something like

if data is not None:

data = datetime_safe.datetime.strptime(data, input_format).date()

else:

data = None

comment:11 Changed 2 years ago by vosi

sorry, previous one was rather stupid )))
it would be better to

try:
  input_format = get_format('DATE_INPUT_FORMATS')[0]
  data = datetime.datetime.strptime(data, input_format).date()
except (TypeError, ValueError):
  pass
Last edited 2 years ago by vosi (previous) (diff)

comment:12 Changed 2 years ago by vosi

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:13 Changed 2 years ago by anonymous

This is a duplicate of: #17542 that is already fixed

comment:14 Changed 2 years ago by jezdez

  • Resolution set to duplicate
  • Status changed from reopened to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.