Opened 8 years ago

Closed 8 years ago

Last modified 5 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:


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().

Change History (5)

comment:1 Changed 8 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 8 years ago by gav

  • Keywords qsrf-cleanup added

comment:3 Changed 8 years ago by jacob

  • milestone set to 1.0

comment:4 Changed 8 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 5 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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