﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30044	A FieldError should be raised when trying to update with F reference to MTI inherited field	Tom Carrick	nobody	"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."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	1	0	0	0	0	0
