Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#7944 closed (fixed)

Generic date based views get confused with a numeric month_format

Reported by: Chris Beaven Owned by: Justin Lilly
Component: Generic views Version: master
Severity: Keywords:
Cc: justinlilly@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

Currently, the views are doing
*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])

Which causes problems if someone is using a numeric month_format.

a date of 2008-1-14 is converted to "2008114", which is read as 2008-11-4

Easy fix, just use a delimiter in the strptime method

Attachments (5)

strptime_delimiters.patch (1.8 KB) - added by justinlilly@… 8 years ago.
added strptime delimiters
strptime_delimiters2.patch (1.8 KB) - added by justinlilly@… 8 years ago.
now with - delimiters instead of delimiters
strptime_delimiters3.patch (4.1 KB) - added by Justin Lilly 8 years ago.
Testing added.
strptime_delimiters4.patch (4.4 KB) - added by Alex Gaynor 8 years ago.
added a templae for the day view
date_based_one_digit_month_confusion.patch (1.1 KB) - added by Ryszard Szopa <ryszard.szopa@…> 8 years ago.

Download all attachments as: .zip

Change History (21)

comment:1 Changed 8 years ago by Chris Beaven

Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Chris Beaven

Tests for day-related views (which are the only ones which will have this bug) can be found in #1282. It'd be easier if that was merged and then the patch written against that...

comment:3 Changed 8 years ago by anonymous

Cc: justinlilly@… added

Changed 8 years ago by justinlilly@…

Attachment: strptime_delimiters.patch added

added strptime delimiters

comment:4 Changed 8 years ago by Chris Beaven

I've had problems in the past doing this with just spaces (some weird bug with strptime).
To be safer, I'd use a dash as the delimiter.

Changed 8 years ago by justinlilly@…

Attachment: strptime_delimiters2.patch added

now with - delimiters instead of delimiters

comment:5 Changed 8 years ago by Chris Beaven

Has patch: set
Needs tests: set

The tests in #1282 can be augmented to test for this bug.

comment:6 Changed 8 years ago by Justin Lilly

Owner: changed from nobody to Justin Lilly
Status: newassigned

Changed 8 years ago by Justin Lilly

Attachment: strptime_delimiters3.patch added

Testing added.

Changed 8 years ago by Alex Gaynor

Attachment: strptime_delimiters4.patch added

added a templae for the day view

comment:7 Changed 8 years ago by Ramiro Morales

#10022 was a duplicate and included a patch too

Changed 8 years ago by Ryszard Szopa <ryszard.szopa@…>

comment:8 Changed 8 years ago by Ryszard Szopa <ryszard.szopa@…>

I attached my patch from the closed #10022. It may do a better job as it will keep working no matter what is put into month_format, which could include the delimiter.

comment:9 Changed 8 years ago by Ryszard Szopa <ryszard.szopa@…>

BTW when a fix for this bug is going to make it to the repo? (Please excuse me if this is the wrong place to ask such a question.)

comment:10 in reply to:  8 Changed 8 years ago by Ramiro Morales

Replying to Ryszard Szopa <ryszard.szopa@gmail.com>:

I attached my patch from the closed #10022. It may do a better job as it will keep working no matter what is put into month_format, which could include the delimiter.

Then you may want to include the tests already included in the other patches and possibly expand them to demonstrate the distinctive feature you describe. This (the existence of tests) would increase the probabilities of this ticket being fixed with a commit.

comment:11 in reply to:  8 ; Changed 8 years ago by Justin Lilly

Replying to Ryszard Szopa <ryszard.szopa@gmail.com>:

I attached my patch from the closed #10022. It may do a better job as it will keep working no matter what is put into month_format, which could include the delimiter.

I'm not quite sure what your patch offers that mine does not. And unless I'm missing something else, you shouldn't be accepting delimiters from month_format. According to the docs, month_format should only accept strftime style arguments like %m or %b.

As it stands now, this ticket should be RFC, it just needs to be reviewed by someone and marked that way. If there is a flaw in my thinking, please let me know, but I don't think your patch solves the problem.

comment:12 Changed 8 years ago by Justin Lilly

milestone: 1.1

Also, I'd like to see this in 1.1 as its an easy bugfix.

comment:13 in reply to:  11 Changed 8 years ago by Ryszard Szopa <ryszard.szopa@…>

Replying to justinlilly:

I'm not quite sure what your patch offers that mine does not. And unless I'm missing something else, you shouldn't be accepting delimiters from month_format. According to the docs, month_format should only accept strftime style arguments like %m or %b.

As it stands now, this ticket should be RFC, it just needs to be reviewed by someone and marked that way. If there is a flaw in my thinking, please let me know, but I don't think your patch solves the problem.

Both patches seem to fix the problem. You've included a test case, so you should be the winner ;-)

(Whatever gets into the release, I will be happy to see that bug finally fixed.)

comment:14 Changed 8 years ago by Jacob

Resolution: fixed
Status: assignedclosed

(In [10457]) Fixed #7944: date-based generic views no longer get confused with a numeric month format. Thanks to Justin Lilly and Alex Gaynor.

comment:15 Changed 8 years ago by Jacob

(In [10459]) [1.0.X] Fixed #7944: date-based generic views no longer get confused with a numeric month format. Thanks to Justin Lilly and Alex Gaynor. Backport of r10457 and r10458 from trunk.

comment:16 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top