Fixed #30044 -- Raised a FieldError on inherited field update attempts.
This commit is contained in:
parent
4fc35a9c3e
commit
9e5e5a657b
|
@ -1600,6 +1600,8 @@ class Query:
|
||||||
field_list = name.split(LOOKUP_SEP)
|
field_list = name.split(LOOKUP_SEP)
|
||||||
join_info = self.setup_joins(field_list, self.get_meta(), self.get_initial_alias(), can_reuse=reuse)
|
join_info = self.setup_joins(field_list, self.get_meta(), self.get_initial_alias(), can_reuse=reuse)
|
||||||
targets, final_alias, join_list = self.trim_joins(join_info.targets, join_info.joins, join_info.path)
|
targets, final_alias, join_list = self.trim_joins(join_info.targets, join_info.joins, join_info.path)
|
||||||
|
if not allow_joins and len(join_list) > 1:
|
||||||
|
raise FieldError('Joined field references are not permitted in this query')
|
||||||
if len(targets) > 1:
|
if len(targets) > 1:
|
||||||
raise FieldError("Referencing multicolumn fields with F() objects "
|
raise FieldError("Referencing multicolumn fields with F() objects "
|
||||||
"isn't supported")
|
"isn't supported")
|
||||||
|
|
|
@ -15,6 +15,10 @@ class Employee(models.Model):
|
||||||
return '%s %s' % (self.firstname, self.lastname)
|
return '%s %s' % (self.firstname, self.lastname)
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteEmployee(Employee):
|
||||||
|
adjusted_salary = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
class Company(models.Model):
|
class Company(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
num_employees = models.PositiveIntegerField()
|
num_employees = models.PositiveIntegerField()
|
||||||
|
|
|
@ -24,8 +24,8 @@ from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
|
||||||
from django.test.utils import Approximate
|
from django.test.utils import Approximate
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
UUID, UUIDPK, Company, Employee, Experiment, Number, Result, SimulationRun,
|
UUID, UUIDPK, Company, Employee, Experiment, Number, RemoteEmployee,
|
||||||
Time,
|
Result, SimulationRun, Time,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -285,6 +285,11 @@ class BasicExpressionsTests(TestCase):
|
||||||
with self.assertRaisesMessage(FieldError, msg):
|
with self.assertRaisesMessage(FieldError, msg):
|
||||||
test_gmbh.save()
|
test_gmbh.save()
|
||||||
|
|
||||||
|
def test_update_inherited_field_value(self):
|
||||||
|
msg = 'Joined field references are not permitted in this query'
|
||||||
|
with self.assertRaisesMessage(FieldError, msg):
|
||||||
|
RemoteEmployee.objects.update(adjusted_salary=F('salary') * 5)
|
||||||
|
|
||||||
def test_object_update_unsaved_objects(self):
|
def test_object_update_unsaved_objects(self):
|
||||||
# F expressions cannot be used to update attributes on objects which do
|
# F expressions cannot be used to update attributes on objects which do
|
||||||
# not yet exist in the database
|
# not yet exist in the database
|
||||||
|
|
Loading…
Reference in New Issue