Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#7944 closed (fixed)

Generic date based views get confused with a numeric month_format

Reported by: SmileyChris Owned by: justinlilly
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@… 7 years ago.
added strptime delimiters
strptime_delimiters2.patch (1.8 KB) - added by justinlilly@… 7 years ago.
now with - delimiters instead of delimiters
strptime_delimiters3.patch (4.1 KB) - added by justinlilly 7 years ago.
Testing added.
strptime_delimiters4.patch (4.4 KB) - added by Alex 7 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@…> 7 years ago.

Download all attachments as: .zip

Change History (21)

comment:1 Changed 7 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 7 years ago by SmileyChris

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 7 years ago by anonymous

  • Cc justinlilly@… added

Changed 7 years ago by justinlilly@…

added strptime delimiters

comment:4 Changed 7 years ago by SmileyChris

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 7 years ago by justinlilly@…

now with - delimiters instead of delimiters

comment:5 Changed 7 years ago by SmileyChris

  • Has patch set
  • Needs tests set

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

comment:6 Changed 7 years ago by justinlilly

  • Owner changed from nobody to justinlilly
  • Status changed from new to assigned

Changed 7 years ago by justinlilly

Testing added.

Changed 7 years ago by Alex

added a templae for the day view

comment:7 Changed 7 years ago by ramiro

#10022 was a duplicate and included a patch too

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

comment:8 follow-ups: Changed 7 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 7 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 7 years ago by ramiro

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 ; follow-up: Changed 6 years ago by justinlilly

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 6 years ago by justinlilly

  • milestone set to 1.1

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

comment:13 in reply to: ↑ 11 Changed 6 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 6 years ago by jacob

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

(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 6 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 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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