From: Mike Bayer Date: Mon, 22 Apr 2013 21:24:31 +0000 (-0400) Subject: tweak this some more to handle the array being empty again X-Git-Tag: rel_0_8_1~8^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63c211f42730011760aa8e3f88b2171b23bc0a60;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git tweak this some more to handle the array being empty again --- diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 82660d96c7..5d9368893a 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -671,11 +671,9 @@ class ARRAY(sqltypes.Concatenable, sqltypes.TypeEngine): def _proc_array(self, arr, itemproc, dim, collection): if dim is None: - if arr is None: - arr = [] - else: - arr = list(arr) - if dim == 1 or dim is None and not hasattr(arr[0], '__iter__'): + arr = list(arr) + if dim == 1 or dim is None and ( + not arr or not hasattr(arr[0], '__iter__')): if itemproc: return collection(itemproc(x) for x in arr) else: diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 42c8c85c47..e217eb0b81 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -2247,6 +2247,17 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): 7 ) + def test_undim_array_empty(self): + arrtable = self.tables.arrtable + self._fixture_456(arrtable) + eq_( + testing.db.scalar( + select([arrtable.c.intarr]). + where(arrtable.c.intarr.contains([])) + ), + [4, 5, 6] + ) + def test_array_getitem_slice_exec(self): arrtable = self.tables.arrtable testing.db.execute(