mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #29745 -- Based Expression equality on detailed initialization signature.
The old implementation considered objects initialized with an equivalent signature different if some arguments were provided positionally instead of as keyword arguments. Refs #11964, #26167.
This commit is contained in:
parent
e4df8e6dc0
commit
bc7e288ca9
2 changed files with 57 additions and 24 deletions
|
@ -11,8 +11,9 @@ from django.db.models.aggregates import (
|
|||
Avg, Count, Max, Min, StdDev, Sum, Variance,
|
||||
)
|
||||
from django.db.models.expressions import (
|
||||
Case, Col, Combinable, Exists, ExpressionList, ExpressionWrapper, F, Func,
|
||||
OrderBy, OuterRef, Random, RawSQL, Ref, Subquery, Value, When,
|
||||
Case, Col, Combinable, Exists, Expression, ExpressionList,
|
||||
ExpressionWrapper, F, Func, OrderBy, OuterRef, Random, RawSQL, Ref,
|
||||
Subquery, Value, When,
|
||||
)
|
||||
from django.db.models.functions import (
|
||||
Coalesce, Concat, Length, Lower, Substr, Upper,
|
||||
|
@ -822,6 +823,31 @@ class ExpressionsTests(TestCase):
|
|||
)
|
||||
|
||||
|
||||
class SimpleExpressionTests(SimpleTestCase):
|
||||
|
||||
def test_equal(self):
|
||||
self.assertEqual(Expression(), Expression())
|
||||
self.assertEqual(
|
||||
Expression(models.IntegerField()),
|
||||
Expression(output_field=models.IntegerField())
|
||||
)
|
||||
self.assertNotEqual(
|
||||
Expression(models.IntegerField()),
|
||||
Expression(models.CharField())
|
||||
)
|
||||
|
||||
def test_hash(self):
|
||||
self.assertEqual(hash(Expression()), hash(Expression()))
|
||||
self.assertEqual(
|
||||
hash(Expression(models.IntegerField())),
|
||||
hash(Expression(output_field=models.IntegerField()))
|
||||
)
|
||||
self.assertNotEqual(
|
||||
hash(Expression(models.IntegerField())),
|
||||
hash(Expression(models.CharField())),
|
||||
)
|
||||
|
||||
|
||||
class ExpressionsNumericTests(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue