Opened 16 years ago

Closed 16 years ago

#6088 closed (fixed)

get_previous_in_order broken

Reported by: James Wheare <django@…> Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: qs-rf-fixed
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There's a bug in the SQL generated when calling get_previous_in_order. Luckily looks like a quick fix from where I'm sitting. Just need to change the ordering to DESC from ASC.

Attachments (1)

_get_next_or_previous_in_order.diff (743 bytes ) - added by James Wheare <django@…> 16 years ago.

Download all attachments as: .zip

Change History (6)

by James Wheare <django@…>, 16 years ago

comment:1 by James Wheare <django@…>, 16 years ago

Has patch: set

This is the SQL run when calling get_next_in_order on a "model" object with _order 24

SELECT * FROM app_model WHERE fk = 1 AND _order > 24 ORDER BY app_model._order ASC LIMIT 1;

And here's get_previous_in_order on the same object

SELECT * FROM app_model WHERE fk = 1 AND _order < 24 ORDER BY app_model._order ASC LIMIT 1;

The patch changes that second query to use DESC instead.

comment:2 by Malcolm Tredinnick, 16 years ago

Keywords: qs-rf added

I'll fix this on queryset-refactor, rather than trunk, but it looks basically correct.

comment:3 by Malcolm Tredinnick, 16 years ago

Keywords: qs-rf-fixed added; qs-rf removed

Through the magic of time machines, I fixed this back in [6486].

I'll note in passing, though, that the patch on this ticket isn't correct. The idiom

is_next and '' or '-'

is invalid when the second argument to the "and" portion evaluates to False. This expression will always return '-', regardless of the value of is_next. The code in [6486] avoids this trap.

Ticket will be closed when queryset-refactor is merged into trunk.

comment:4 by Chris Beaven, 16 years ago

Triage Stage: UnreviewedAccepted

Promoting to accepted: if it's fixed in the queryset refactor then it has obviously an accepted issue (even if the ticket isn't correct)

comment:5 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658

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