#12240 closed (fixed)
select_related doesn't work correctly when mixing nullable and non-nullable keys
| Reported by: | Michał Bartoszkiewicz | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.1 |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The following models:
class Model1(models.Model):
x = models.ForeignKey('Model2', null=True)
class Model2(models.Model):
y = models.ForeignKey('Model3', null=False)
class Model3(models.Model):
z = models.ForeignKey('Model4', null=False)
class Model4(models.Model):
q = models.IntegerField()
cause a problem with select_related():
In [4]: models.Model1.objects.select_related('x__y')
Out[4]: [<Model1: Model1 object>]
In [5]: models.Model1.objects.select_related('x__y__z')
Out[5]: []
It look like the fix for #7369 only fixed a case when a single non-nullable ForeignKey is encountered, not when there are two in a row.
Attachments (2)
Change History (8)
by , 16 years ago
| Attachment: | django-12240.diff added |
|---|
comment:1 by , 16 years ago
| Has patch: | set |
|---|
comment:2 by , 16 years ago
| milestone: | → 1.2 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
by , 16 years ago
| Attachment: | django-select-related-join-chain.diff added |
|---|
comment:3 by , 16 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:4 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:5 by , 16 years ago
Note:
See TracTickets
for help on using tickets.
The attached patch fixes the problem for me.