Changes between Version 1 and Version 6 of Ticket #31246


Ignore:
Timestamp:
Feb 10, 2020, 1:48:48 AM (5 years ago)
Author:
Abhijeet Viswa
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #31246

    • Property Keywords select_for_update; mti; relations; → select_for_update mti relations
    • Property Severity NormalRelease blocker
    • Property Triage Stage UnreviewedAccepted
    • Property Version master2.2
    • Property Has patch set
    • Property Patch needs improvement set
    • Property Needs tests set
    • Property Summary Related Model with inheritance generates wrong select_for_update 'of'select_for_update() with "of" uses wrong tables from (multi-level) model inheritance.
  • Ticket #31246 – Description

    v1 v6  
     1Two different bugs related to model inheritance:
     21.
    13Consider the following models:
    24
     
    3436The `of` clause in the generated SQL references the model `a` instead of `b`
    3537
     382.
     39 Consider the following models:
     40 
     41{{{
     42class A(models.Model):
     43    field1 = models.IntegerField()
     44
     45class B(A):
     46     field2 = models.IntegerField()
     47 
     48class C(B):
     49    field_c = models.IntegerField()
     50}}}
     51
     52{{{
     53queryset = C.objects.all().select_for_update(of=('b_ptr', 'b_ptr__a_ptr'))
     54}}}
     55 
     56The above queryset crashes with the following crashlog:
     57
     58{{{
     59Traceback (most recent call last):
     60  File "/home/abhijeet/git-repos/django/django/core/management/base.py", line 328, in run_from_argv
     61    self.execute(*args, **cmd_options)
     62  File "/home/abhijeet/git-repos/django/django/core/management/base.py", line 369, in execute
     63   output = self.handle(*args, **options)
     64  File "/home/abhijeet/django_contrib/selectforupdate/management/commands/debug.py", line 12, in handle
     65    print(queryset.query)
     66  File "/home/abhijeet/git-repos/django/django/db/models/sql/query.py", line 257, in __str__
     67    sql, params = self.sql_with_params()
     68  File "/home/abhijeet/git-repos/django/django/db/models/sql/query.py", line 265, in sql_with_params
     69    return self.get_compiler(DEFAULT_DB_ALIAS).as_sql()
     70  File "/home/abhijeet/git-repos/django/django/db/models/sql/compiler.py", line 555, in as_sql
     71    of=self.get_select_for_update_of_arguments(),
     72  File "/home/abhijeet/git-repos/django/django/db/models/sql/compiler.py", line 1036, in get_select_for_update_of_arguments
     73    select_index = klass_info['select_fields'][0]
     74IndexError: list index out of range
     75}}}
     76
    3677This is related to #30953
Back to Top