From 4bb8397ae3a9d65bd18eb1d7c951bf5121ea280a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 6 Oct 2017 11:14:29 -0400 Subject: Fix array_agg to accommodate ARRAY arguments Fixed bug in :func:`.array_agg` function where passing an argument that is already of type :class:`.ARRAY`, such as a Postgresql :obj:`.postgresql.array` construct, would produce a ``ValueError``, due to the function attempting to nest the arrays. Change-Id: Ibe5f6275d90e4868e6ef8a733de05acd44c05d78 Fixes: #4107 --- lib/sqlalchemy/sql/functions.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql/functions.py') diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index 9a9396fec..23bd9a568 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -689,7 +689,14 @@ class array_agg(GenericFunction): def __init__(self, *args, **kwargs): args = [_literal_as_binds(c) for c in args] - kwargs.setdefault('type_', self.type(_type_from_args(args))) + + if 'type_' not in kwargs: + + type_from_args = _type_from_args(args) + if isinstance(type_from_args, sqltypes.ARRAY): + kwargs['type_'] = type_from_args + else: + kwargs['type_'] = sqltypes.ARRAY(type_from_args) kwargs['_parsed_args'] = args super(array_agg, self).__init__(*args, **kwargs) -- cgit v1.2.1