Skip to content

Commit 539e739

Browse files
author
James William Pye
committed
Fix array NULL unpacking.
Add a test to validate functionality. Reported by Elvis.
1 parent c081be8 commit 539e739

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

postgresql/documentation/changes.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Changes
44
1.0.1 in development
55
--------------------
66

7-
* First .first()'s handling of counts and commands.
7+
* Fix unpacking of array NULLs. (Elvis Pranskevichus)
8+
* Fix .first()'s handling of counts and commands.
89
Bad logic caused zero-counts to return the command tag.
910
* Don't interrupt and close a temporal connection if it's not open.
1011
* Use the Driver's typio attribute for TypeIO overrides. (Elvis Pranskevichus)

postgresql/driver/pq3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def pack_an_array(data, get_parts = self.array_parts):
349349
if hasbin_output:
350350
def unpack_an_array(data, array_from_parts = self.array_from_parts):
351351
flags, typoid, dims, lbs, elements = array_unpack(data)
352-
return array_from_parts((map(unpack_element, elements), dims, lbs))
352+
return array_from_parts(((x if x is None else unpack_element(x) for x in elements), dims, lbs))
353353
else:
354354
# signals string formatting
355355
unpack_an_array = None

postgresql/test/test_driver.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,5 +1753,17 @@ def testIdentify(self):
17531753
# It just exercises the code path.
17541754
db.typio.identify(contrib_hstore = 'pg_catalog.reltime')
17551755

1756+
@pg_tmp
1757+
def testArrayNulls(self):
1758+
try:
1759+
sqlexec('SELECT ARRAY[1,NULL]::int[]')
1760+
except Exception:
1761+
# unsupported here
1762+
return
1763+
inta = prepare('select $1::int[]').first
1764+
texta = prepare('select $1::text[]').first
1765+
self.failUnlessEqual(inta([1,2,None]), [1,2,None])
1766+
self.failUnlessEqual(texta(["foo",None,"bar"]), ["foo",None,"bar"])
1767+
17561768
if __name__ == '__main__':
17571769
unittest.main()

0 commit comments

Comments
 (0)