#28944: Chaining values()/values_list() after QuerySet.select_for_update(of=())
crashes
-------------------------------------+-------------------------------------
Reporter: Thierry Bastian | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Thierry Bastian):
* status: closed => new
* resolution: fixed =>
Comment:
Ok so you fixed the simple case with self, but it still fails where there
are joins.
So if you have 2 models:
{{{
class A(models.Model):
foo = models.TextField()
class B(models.Model):
bla = models.TextField()
a = models.ForeignKey(a, on_delete=models.CASCADE)
and then if you want to do:
B.objects.all().select_related('a').select_for_update(of=('self', 'a')) ,
that works
but the same with a values_list:
B.objects.all().select_related('a').select_for_update(of=('self',
'a')).values_list('pk', 'a__foo'), that does not work and results in
something like (I have different class names in my code)
Traceback (most recent call last):
File "<console>", line 2, in <module>
File "/usr/local/filewave/python/lib/python3.6/site-
packages/django/db/models/query.py", line 248, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/local/filewave/python/lib/python3.6/site-
packages/django/db/models/query.py", line 272, in __iter__
self._fetch_all()
File "/usr/local/filewave/python/lib/python3.6/site-
packages/django/db/models/query.py", line 1179, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/local/filewave/python/lib/python3.6/site-
packages/django/db/models/query.py", line 139, in __iter__
return compiler.results_iter(tuple_expected=True,
chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/usr/local/filewave/python/lib/python3.6/site-
packages/django/db/models/sql/compiler.py", line 1015, in results_iter
results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch,
chunk_size=chunk_size)
File "/usr/local/filewave/python/lib/python3.6/site-
packages/django/db/models/sql/compiler.py", line 1051, in execute_sql
sql, params = self.as_sql()
File "/usr/local/filewave/python/lib/python3.6/site-
packages/django/db/models/sql/compiler.py", line 508, in as_sql
of=self.get_select_for_update_of_arguments(),
File "/usr/local/filewave/python/lib/python3.6/site-
packages/django/db/models/sql/compiler.py", line 962, in
get_select_for_update_of_arguments
', '.join(_get_field_choices()),
django.core.exceptions.FieldError: Invalid field name(s) given in
select_for_update(of=(...)): mdm_client. Only relational fields followed
in the query are allowed. Choices are: self.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28944#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.1ed2c1efa5b271bffe364f2b75b92c6f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.