From 56f6001d6df966227623351f5e8b755ee561db6a Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Tue, 23 Sep 2008 09:11:11 +0200 Subject: [PATCH] Support for NULLs in UUID --- ChangeLog | 5 +++++ lib/extras.py | 4 ++-- tests/types_extras.py | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5912c973..309e1fc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-09-23 Federico Di Gregorio + + * Applied patch from Brian Sutherland that fixes NULL + valus in UUID support. + 2008-09-19 Federico Di Gregorio * lib/extras.py: added UUID support, modeled after the code diff --git a/lib/extras.py b/lib/extras.py index 91ab9ab6..67a67f20 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -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 @@ -321,4 +321,4 @@ except ImportError, e: raise e -__all__ = [ k for k in locals().keys() if not k.startswith('_') ] \ No newline at end of file +__all__ = [ k for k in locals().keys() if not k.startswith('_') ] diff --git a/tests/types_extras.py b/tests/types_extras.py index 94b99271..421a7294 100644 --- a/tests/types_extras.py +++ b/tests/types_extras.py @@ -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__)