Opened 6 years ago
Last modified 6 years ago
#31246 closed Bug
Related Model with inheritance generates wrong select_for_update 'of' — at Version 1
| Reported by: | Abhijeet Viswa | Owned by: | Abhijeet Viswa |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 2.2 |
| Severity: | Release blocker | Keywords: | select_for_update mti relations |
| 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 (last modified by )
Consider the following models:
class A(models.Model):
field1 = models.IntegerField()
class B(A):
field2 = models.IntegerField()
class C(models.Model):
b = models.ForeignKey(B, on_delete=models.CASCADE)
queryset = C.objects.select_related('b').select_for_update(of=('b'))
The above queryet generates the following query:
SELECT "selectforupdate_c"."id",
"selectforupdate_c"."b_id",
"selectforupdate_a"."id",
"selectforupdate_a"."field1",
"selectforupdate_b"."a_ptr_id",
"selectforupdate_b"."field2"
FROM "selectforupdate_c"
INNER JOIN "selectforupdate_b"
ON ( "selectforupdate_c"."b_id" =
"selectforupdate_b"."a_ptr_id" )
INNER JOIN "selectforupdate_a"
ON ( "selectforupdate_b"."a_ptr_id" = "selectforupdate_a"."id" )
FOR UPDATE OF "selectforupdate_a"
The of clause in the generated SQL references the model a instead of b
This is related to #30953
Note:
See TracTickets
for help on using tickets.