#30044: F expressions don't work with MTI
-------------------------------------+-------------------------------------
               Reporter:  Tom        |          Owner:  nobody
  Carrick                            |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 First, I'm not sure if it is or should be possible to do this, but I think
 at least the error message could be improved.


 {{{
 class Parent(models.Model):
     date_x = models.DateTimeField(blank=True, null=True)

 class Child(Parent):
     date_y = models.DateTimeField(blank=True, null=True)


 >>> Child.objects.update(date_y=F('date_x'))
 Traceback (most recent call last):
   File "/Users/tom/.local/share/virtualenvs/test-PwakbHlc/lib/python3.6
 /site-packages/django/db/backends/utils.py", line 85, in _execute
     return self.cursor.execute(sql, params)
   File "/Users/tom/.local/share/virtualenvs/test-PwakbHlc/lib/python3.6
 /site-packages/django/db/backends/sqlite3/base.py", line 296, in execute
     return Database.Cursor.execute(self, query, params)
 sqlite3.OperationalError: no such column: mtitest_parent.date_x
 }}}

 This error is confusing as it says it's looking at the parent model, but
 the field is right there on the parent model.

 On another project using postgres, the error is better but it makes it
 seem like a bug in django (not sure if it is or isn't):

 {{{
 >>> Project.objects.update(deactivation_date=F('last_activity'))
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/local/lib/python3.5/site-
 packages/django/db/models/manager.py", line 82, in manager_method
     return getattr(self.get_queryset(), name)(*args, **kwargs)
   File "/usr/local/lib/python3.5/site-packages/django/db/models/query.py",
 line 695, in update
     rows = query.get_compiler(self.db).execute_sql(CURSOR)
   File "/usr/local/lib/python3.5/site-
 packages/django/db/models/sql/compiler.py", line 1379, in execute_sql
     cursor = super().execute_sql(result_type)
   File "/usr/local/lib/python3.5/site-
 packages/django/db/models/sql/compiler.py", line 1068, in execute_sql
     cursor.execute(sql, params)
   File "/usr/local/lib/python3.5/site-
 packages/django/db/backends/utils.py", line 100, in execute
     return super().execute(sql, params)
   File "/usr/local/lib/python3.5/site-
 packages/raven/contrib/django/client.py", line 123, in execute
     return real_execute(self, sql, params)
   File "/usr/local/lib/python3.5/site-
 packages/django/db/backends/utils.py", line 68, in execute
     return self._execute_with_wrappers(sql, params, many=False,
 executor=self._execute)
   File "/usr/local/lib/python3.5/site-
 packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
     return executor(sql, params, many, context)
   File "/usr/local/lib/python3.5/site-
 packages/django/db/backends/utils.py", line 85, in _execute
     return self.cursor.execute(sql, params)
   File "/usr/local/lib/python3.5/site-packages/django/db/utils.py", line
 89, in __exit__
     raise dj_exc_value.with_traceback(traceback) from exc_value
   File "/usr/local/lib/python3.5/site-
 packages/django/db/backends/utils.py", line 85, in _execute
     return self.cursor.execute(sql, params)
 django.db.utils.ProgrammingError: missing FROM-clause entry for table
 "content_contentmodel"
 LINE 1: ...DATE "projects_project" SET "deactivation_date" = "content_c...
                                                              ^
 missing FROM-clause entry for table "content_contentmodel"
 LINE 1: ...DATE "projects_project" SET "deactivation_date" = "content_c...
 }}}

 I don't know if it's possible to fix this, but if not it would be nice if
 the user could be informed this isn't possible.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30044>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.18ae7e7d9cb4e01a52a1eebfdb5e148c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to