Code

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#724 closed defect (fixed)

get_next_by_pub_date/get_previous_by_pub_date model methods only see 1 item for each day.

Reported by: mattycakes@… Owned by: adrian
Component: Core (Other) Version:
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The model.get_next_by_pub_date() and model.get_previous_by_pub_date() methods appear to only see one item for each day.

For example, I have a blog.posts model in which pub_date is a DateTimeField. If there are multiple posts in one day, the above methods will only see the first post for each day, and then skip to the next day. This is clearly wrong behaviour; the method should retrieve the next item by date whether it was created the same day or not.

Example:

item1.pub_date = 2005/01/01 12:00
item2.pub_date = 2005/01/02 8:00
item3.pub_date = 2005/01/02 9:00

item1.get_next… = item2
item2.get_next… = None
item3.get_prev… = item1

Attachments (1)

lookup_patch.txt (554 bytes) - added by mattycakes@… 9 years ago.
Patch to lookup API tests

Download all attachments as: .zip

Change History (5)

comment:1 Changed 9 years ago by mattycakes@…

  • Severity changed from major to minor

In fact, it only has this problem if multiple items have the same time as well as the same date.

Example:

item1.pub_date = 2005/01/01 12:00
item2.pub_date = 2005/01/02 8:07
item3.pub_date = 2005/01/02 8:07

item1.get_next… = item2
item2.get_next… = None
item3.get_prev… = item1

The above is valid; my first example, however, is wrong.

comment:2 Changed 9 years ago by adrian

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

In [1152] I added some unit tests for this. I can't recreate the problem -- the tests run fine. Please reopen with more information on how to recreate the bug.

comment:3 Changed 9 years ago by mattycakes@…

  • Resolution invalid deleted
  • Status changed from closed to reopened

I've added a few tests. Hopefully these help clarify the problem.

Index: tests/testapp/models/lookup.py
===================================================================
--- tests/testapp/models/lookup.py	(revision 1154)
+++ tests/testapp/models/lookup.py	(working copy)
@@ -103,4 +103,16 @@
 Article 4
 >>> a5.get_previous_by_pub_date()
 Article 6
+>>> a4.get_previous_by_pub_date()
+Article 3
+>>> a3.get_previous_by_pub_date()
+Article 2
+>>> a2.get_previous_by_pub_date()
+Article 1
+>>> a1.get_next_by_pub_date()
+Article 2
+>>> a2.get_next_by_pub_date()
+Article 3
+>>> a3.get_next_by_pub_date()
+Article 4
 """

Changed 9 years ago by mattycakes@…

Patch to lookup API tests

comment:4 Changed 9 years ago by adrian

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

(In [1155]) Fixed #724 -- Ensured get_next_by_FOO() and get_previous_by_FOO() methods don't skip or duplicate any records in the case of duplicate values. Thanks for reporting the bug, mattycakes@…

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.