Support for NULLs in UUID

This commit is contained in:
Federico Di Gregorio 2008-09-23 09:11:11 +02:00
parent b92601306e
commit 56f6001d6d
3 changed files with 10 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2008-09-23 Federico Di Gregorio <fog@initd.org>
* Applied patch from Brian Sutherland that fixes NULL
valus in UUID support.
2008-09-19 Federico Di Gregorio <fog@initd.org>
* lib/extras.py: added UUID support, modeled after the code

View File

@ -306,7 +306,7 @@ try:
"""Create the UUID type and an uuid.UUID adapter."""
if not oid: oid = 2950
_ext.UUID = _ext.new_type((oid, ), "UUID",
lambda data, cursor: uuid.UUID(data))
lambda data, cursor: data and uuid.UUID(data) or None)
_ext.register_type(_ext.UUID)
_ext.register_adapter(uuid.UUID, UUID_adapter)
return _ext.UUID

View File

@ -45,6 +45,9 @@ class TypesBasicTests(unittest.TestCase):
u = uuid.UUID('9c6d5a77-7256-457e-9461-347b4358e350');
s = self.execute("SELECT %s AS foo", (u,))
self.failUnless(u == s)
# must survive NULL cast to a uuid
s = self.execute("SELECT NULL::uuid AS foo")
self.failUnless(s is None)
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)