Refs #24887 -- Stopped mutating a test expression during as_sql().

Also defined an explicit output_field as it was mixing an expression with an
IntegerField() with one with a DecimalField().
This commit is contained in:
Simon Charette 2017-07-13 02:46:44 -04:00
parent 7dfe03f86d
commit 160969d970
1 changed files with 5 additions and 2 deletions

View File

@ -1099,9 +1099,12 @@ class AggregateTestCase(TestCase):
def test_multi_arg_aggregate(self):
class MyMax(Max):
output_field = DecimalField()
def as_sql(self, compiler, connection):
self.set_source_expressions(self.get_source_expressions()[0:1])
return super().as_sql(compiler, connection)
copy = self.copy()
copy.set_source_expressions(copy.get_source_expressions()[0:1])
return super(MyMax, copy).as_sql(compiler, connection)
with self.assertRaisesMessage(TypeError, 'Complex aggregates require an alias'):
Book.objects.aggregate(MyMax('pages', 'price'))