Refs #28897 -- Added test for QuerySet.update() on querysets ordered by inline m2m annotation.

This commit is contained in:
David Wobrock 2022-06-17 09:19:49 +02:00 committed by Mariusz Felisiak
parent e286ce17ff
commit f4680a112d
3 changed files with 13 additions and 0 deletions

View File

@ -109,6 +109,11 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"scalar value but it's not implemented (#25287).": {
"expressions.tests.FTimeDeltaTests.test_durationfield_multiply_divide",
},
"UPDATE ... ORDER BY syntax on MySQL/MariaDB does not support ordering by"
"related fields.": {
"update.tests.AdvancedTests."
"test_update_ordered_by_inline_m2m_annotation",
},
}
if "ONLY_FULL_GROUP_BY" in self.connection.sql_mode:
skips.update(

View File

@ -41,6 +41,7 @@ class Foo(models.Model):
class Bar(models.Model):
foo = models.ForeignKey(Foo, models.CASCADE, to_field="target")
m2m_foo = models.ManyToManyField(Foo, related_name="m2m_foo")
x = models.IntegerField(default=0)
class UniqueNumber(models.Model):

View File

@ -225,6 +225,13 @@ class AdvancedTests(TestCase):
new_name=annotation,
).update(name=F("new_name"))
def test_update_ordered_by_inline_m2m_annotation(self):
foo = Foo.objects.create(target="test")
Bar.objects.create(foo=foo)
Bar.objects.order_by(Abs("m2m_foo")).update(x=2)
self.assertEqual(Bar.objects.get().x, 2)
@unittest.skipUnless(
connection.vendor == "mysql",