Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7181 closed (fixed)

Meta ordering on foreign key field which can be None

Reported by: kkulewski@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: qsrf-cleanup
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I have model A which links to model B (using field b, but A.b can be None). In Meta of A I have ordering set to b.

AFAIK simple A.objects.all() select query contains INNER JOIN (in this case I use sqlite, but probably this problem is more popular) with relation B so if for some instance of A, A.b is None then it will be not included in the results of A.objects.all().

Attachments (0)

Change History (5)

comment:1 Changed 6 years ago by Rudolph

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I can confirm that this is also a problem for me (PostgreSQL, latest trunk). See:
my example

comment:2 Changed 6 years ago by gav

  • Keywords qsrf-cleanup added

comment:3 Changed 6 years ago by jacob

  • milestone set to 1.0

comment:4 Changed 6 years ago by mtredinnick

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

(In [7761]) Fixed #7181 -- when ordering by a potentially NULL field, use a left-outer join
so that the ordering doesn't accidentally restrict the result set.

(Ironically, one existing test actually showed this problem, but I was too
dumb to notice the result was incorrect.)

comment:5 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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.