﻿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
33091	A FieldError should be raised when trying to update MTI inherited field with F reference to child field	Shai Berger		"This is the converse of #30044.

In that bug, we made sure a proper error was raised when we do
{{{#!python
ChildModel.objects.update(child_field=F('parent_field'))
}}}
We should similarly make sure a proper error is raised when we do
{{{#!python
ChildModel.objects.update(parent_field=F('child_field'))
}}}
With current main, if we add the obvious test
{{{#!diff
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index 33c5189390..0a97d537fe 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -318,6 +318,11 @@ class BasicExpressionsTests(TestCase):
         with self.assertRaisesMessage(FieldError, msg):
             RemoteEmployee.objects.update(adjusted_salary=F('salary') * 5)
 
+    def test_update_set_inherited_field_from_child(self):
+        msg = 'Joined field references are not permitted in this query'
+        with self.assertRaisesMessage(FieldError, msg):
+            RemoteEmployee.objects.update(salary=F('adjusted_salary') / 5)
+
     def test_object_update_unsaved_objects(self):
         # F expressions cannot be used to update attributes on objects which do
         # not yet exist in the database
}}}
it fails
{{{
======================================================================
FAIL: test_update_set_inherited_field_from_child (expressions.tests.BasicExpressionsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/usr/lib/python3.9/unittest/case.py"", line 59, in testPartExecutor
    yield
  File ""/usr/lib/python3.9/unittest/case.py"", line 592, in run
    self._callTestMethod(testMethod)
  File ""/usr/lib/python3.9/unittest/case.py"", line 550, in _callTestMethod
    method()
  File ""/home/django/django/tests/expressions/tests.py"", line 324, in test_update_set_inherited_field_from_child
    RemoteEmployee.objects.update(salary=F('adjusted_salary') / 5)
  File ""/usr/lib/python3.9/contextlib.py"", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File ""/home/django/django/django/test/testcases.py"", line 687, in _assert_raises_or_warns_cm
    self.assertIn(expected_message, str(getattr(cm, cm_attr)))
  File ""/usr/lib/python3.9/unittest/case.py"", line 1096, in assertIn
    self.fail(self._formatMessage(msg, standardMsg))
  File ""/usr/lib/python3.9/unittest/case.py"", line 668, in fail
    raise self.failureException(msg)
AssertionError: 'Joined field references are not permitted in this query' not found in ""Cannot resolve keyword 'adjusted_salary' into field. Choices are: company_ceo_set, company_point_of_contact_set, firstname, id, lastname, manager, manager_id, remoteemployee, salary""

----------------------------------------------------------------------
}}}"	Cleanup/optimization	new	Database layer (models, ORM)	dev	Normal			Clifford Gama	Accepted	0	0	0	0	0	0
