summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-03-04 19:11:52 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-03-04 19:11:52 +0000
commit5c4c7b0c6793d4cec364fb5fa9c5063feb4827f7 (patch)
tree99ba9b5cdf3757e8f61cb2fd6ff77f029b1f2983
parent48fa41567243b5587083a36943a8add7b0bf2d62 (diff)
parent780213bfefac7046ac889ffbc1c51e0d244dd678 (diff)
downloadsqlalchemy-5c4c7b0c6793d4cec364fb5fa9c5063feb4827f7.tar.gz
Merge "Fix aggregate_order_by issue"
-rw-r--r--doc/build/changelog/unreleased_13/5989.rst6
-rw-r--r--lib/sqlalchemy/dialects/postgresql/ext.py1
-rw-r--r--test/dialect/postgresql/test_types.py25
3 files changed, 29 insertions, 3 deletions
diff --git a/doc/build/changelog/unreleased_13/5989.rst b/doc/build/changelog/unreleased_13/5989.rst
new file mode 100644
index 000000000..cccf227fc
--- /dev/null
+++ b/doc/build/changelog/unreleased_13/5989.rst
@@ -0,0 +1,6 @@
+.. change::
+ :tags: bug, orm, postgresql
+ :tickets: 5989
+
+ Fixed issue where using :class:`_ext.aggregate_order_by` would return
+ ARRAY(NullType) under certain conditions.
diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py
index 71a0aa5a6..959e6597b 100644
--- a/lib/sqlalchemy/dialects/postgresql/ext.py
+++ b/lib/sqlalchemy/dialects/postgresql/ext.py
@@ -57,6 +57,7 @@ class aggregate_order_by(expression.ColumnElement):
def __init__(self, target, *order_by):
self.target = coercions.expect(roles.ExpressionElementRole, target)
+ self.type = self.target.type
_lob = len(order_by)
if _lob == 0:
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py
index b36f50408..b24132f69 100644
--- a/test/dialect/postgresql/test_types.py
+++ b/test/dialect/postgresql/test_types.py
@@ -1280,12 +1280,31 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase):
is_(expr.type.__class__, types.ARRAY)
is_(expr.type.item_type.__class__, Integer)
- def test_array_agg_specific(self):
+ @testing.combinations(
+ ("original", False, False),
+ ("just_enum", True, False),
+ ("just_order_by", False, True),
+ ("issue_5989", True, True),
+ id_="iaa",
+ argnames="with_enum, using_aggregate_order_by",
+ )
+ def test_array_agg_specific(self, with_enum, using_aggregate_order_by):
+ from sqlalchemy.dialects.postgresql import aggregate_order_by
from sqlalchemy.dialects.postgresql import array_agg
+ from sqlalchemy.dialects.postgresql import ENUM
- expr = array_agg(column("q", Integer))
+ element_type = ENUM if with_enum else Integer
+ expr = (
+ array_agg(
+ aggregate_order_by(
+ column("q", element_type), column("idx", Integer)
+ )
+ )
+ if using_aggregate_order_by
+ else array_agg(column("q", element_type))
+ )
is_(expr.type.__class__, postgresql.ARRAY)
- is_(expr.type.item_type.__class__, Integer)
+ is_(expr.type.item_type.__class__, element_type)
class ArrayRoundTripTest(object):