mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #36173 -- Stabilized identity of Concat with an explicit output_field.
When Expression.__init__() overrides make use of *args, **kwargs captures their argument values are respectively bound as a tuple and dict instances. These composite values might themselves contain values that require special identity treatments such as Concat(output_field) as it's a Field instance. Refs #30628 which introduced bound Field differentiation but lacked argument captures handling. Thanks erchenstein for the report.
This commit is contained in:
committed by
Mariusz Felisiak
parent
6fcd0440aa
commit
df2c4952df
@@ -1433,6 +1433,29 @@ class SimpleExpressionTests(SimpleTestCase):
|
||||
Expression(TestModel._meta.get_field("other_field")),
|
||||
)
|
||||
|
||||
class InitCaptureExpression(Expression):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# The identity of expressions that obscure their __init__() signature
|
||||
# with *args and **kwargs cannot be determined when bound with
|
||||
# different combinations or *args and **kwargs.
|
||||
self.assertNotEqual(
|
||||
InitCaptureExpression(IntegerField()),
|
||||
InitCaptureExpression(output_field=IntegerField()),
|
||||
)
|
||||
|
||||
# However, they should be considered equal when their bindings are
|
||||
# equal.
|
||||
self.assertEqual(
|
||||
InitCaptureExpression(IntegerField()),
|
||||
InitCaptureExpression(IntegerField()),
|
||||
)
|
||||
self.assertEqual(
|
||||
InitCaptureExpression(output_field=IntegerField()),
|
||||
InitCaptureExpression(output_field=IntegerField()),
|
||||
)
|
||||
|
||||
def test_hash(self):
|
||||
self.assertEqual(hash(Expression()), hash(Expression()))
|
||||
self.assertEqual(
|
||||
|
||||
Reference in New Issue
Block a user