From 9ca1f6eff6f19d1ae074d289c6c4209073351805 Mon Sep 17 00:00:00 2001 From: Bendeguz Csirmaz Date: Tue, 10 Sep 2024 21:12:25 +0800 Subject: [PATCH] Refs #373, Refs #24121 -- Added ColPairs.__repr__(). --- django/db/models/expressions.py | 6 ++++++ tests/expressions/tests.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 36ff097041..667e9f93c6 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1342,6 +1342,12 @@ class ColPairs(Expression): def __iter__(self): return iter(self.get_cols()) + def __repr__(self): + return ( + f"{self.__class__.__name__}({self.alias!r}, {self.targets!r}, " + f"{self.sources!r}, {self.output_field!r})" + ) + def get_cols(self): return [ Col(self.alias, target, source) diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 75aa1b0894..af4cf01fca 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -47,6 +47,7 @@ from django.db.models import ( ) from django.db.models.expressions import ( Col, + ColPairs, Combinable, CombinedExpression, NegatedExpression, @@ -2466,6 +2467,10 @@ class ReprTests(SimpleTestCase): " THEN Value('legal')>", ) self.assertEqual(repr(Col("alias", "field")), "Col(alias, field)") + self.assertEqual( + repr(ColPairs("alias", ["t1", "t2"], ["s1", "s2"], "f")), + "ColPairs('alias', ['t1', 't2'], ['s1', 's2'], 'f')", + ) self.assertEqual(repr(F("published")), "F(published)") self.assertEqual( repr(F("cost") + F("tax")), ""