[Django] #31249: Multilevel Inherited models crashes with select_for_update 'of'

4 views
Skip to first unread message

Django

unread,
Feb 8, 2020, 3:13:36 PM2/8/20
to django-...@googlegroups.com
#31249: Multilevel Inherited models crashes with select_for_update 'of'
-------------------------------------+-------------------------------------
Reporter: Abhijeet | Owner: Abhijeet
Type: Bug | Status: assigned
Component: Database | Version: 2.2
layer (models, ORM) | Keywords: select_for_update
Severity: Normal | mti
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Consider the following models:

{{{
class A(models.Model):
field1 = models.IntegerField()

class B(A):
field2 = models.IntegerField()

class C(B):
field_c = models.IntegerField()
}}}

{{{
queryset = C.objects.all().select_for_update(of=('b_ptr', 'b_ptr__a_ptr'))
}}}

The above queryset crashes with the following crashlog:

{{{
Traceback (most recent call last):
File "/home/abhijeet/git-repos/django/django/core/management/base.py",
line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/abhijeet/git-repos/django/django/core/management/base.py",
line 369, in execute
output = self.handle(*args, **options)
File
"/home/abhijeet/django_contrib/selectforupdate/management/commands/debug.py",
line 12, in handle
print(queryset.query)
File "/home/abhijeet/git-repos/django/django/db/models/sql/query.py",
line 257, in __str__
sql, params = self.sql_with_params()
File "/home/abhijeet/git-repos/django/django/db/models/sql/query.py",
line 265, in sql_with_params
return self.get_compiler(DEFAULT_DB_ALIAS).as_sql()
File "/home/abhijeet/git-repos/django/django/db/models/sql/compiler.py",
line 555, in as_sql
of=self.get_select_for_update_of_arguments(),
File "/home/abhijeet/git-repos/django/django/db/models/sql/compiler.py",
line 1036, in get_select_for_update_of_arguments
select_index = klass_info['select_fields'][0]
IndexError: list index out of range
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31249>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 9, 2020, 1:23:32 AM2/9/20
to django-...@googlegroups.com
#31249: Multilevel Inherited models crashes with select_for_update 'of'
-------------------------------------+-------------------------------------
Reporter: Abhijeet | Owner: Abhijeet
Type: Bug | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: select_for_update | Triage Stage:
mti | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Abhijeet):

My [https://github.com/django/django/pull/12436 PR].

The PR adds a testcase which will fail since it expects #31246 to have
been fixed.

--
Ticket URL: <https://code.djangoproject.com/ticket/31249#comment:1>

Django

unread,
Feb 10, 2020, 2:03:40 AM2/10/20
to django-...@googlegroups.com
#31249: select_for_update() with 'of' crashes with models from multi-level
inheritance.

-------------------------------------+-------------------------------------
Reporter: Abhijeet | Owner: Abhijeet
Type: Bug | Status: closed

Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: select_for_update | Triage Stage:
mti | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: assigned => closed
* resolution: => duplicate


Comment:

I think we can treat this ticket as a duplicate of #31246 because both are
related with using models from model inheritance in `of` argument of
`select_for_update()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/31249#comment:2>

Django

unread,
Feb 10, 2020, 2:07:28 AM2/10/20
to django-...@googlegroups.com
#31249: select_for_update() with 'of' crashes with models from multi-level
inheritance.
-------------------------------------+-------------------------------------
Reporter: Abhijeet | Owner: Abhijeet
Type: Bug | Status: closed
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: select_for_update | Triage Stage:
mti | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Abhijeet):

Replying to [comment:2 felixxm]:


> I think we can treat this ticket as a duplicate of #31246 because both
are related with using models from model inheritance in `of` argument of
`select_for_update()`.

Sounds good. I wasn't sure if I should include this bug in #31246. I
thought it would be best to leave it as a separate ticket.

--
Ticket URL: <https://code.djangoproject.com/ticket/31249#comment:3>

Reply all
Reply to author
Forward
0 new messages