Opened 2 years ago

Closed 2 years ago

#20170 closed Bug (needsinfo)

LIMIT works on entire queryset, even when not expected to.

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.4
Severity: Normal Keywords: ManyToManyField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Class MyParent(models.Model):
    x = models.IntegerField()

Class MyChild(models.Model):
    parent = models.ForeignKey(MyParent)
    y      = models.IntegerField()

x = MyModel1.objects.all()[:5]
x.values('x', 'mychild')

The resulting queryset will possibly return less than 5 objects and then possibly not all of their children (because it adds 'LIMIT 5' to the entire SQL query instead of making one query with 'LIMIT 5' and another one with the join).

Change History (2)

comment:1 Changed 2 years ago by zeevro@…

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

comment:2 Changed 2 years ago by lukeplant

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

I cannot understand the example code - it seems to have several errors. Can you post a corrected example, and re-open? I'm struggling to understand what the bug is as well, and what join you are referring to.

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