diff options
| author | Federico Di Gregorio <fog@initd.org> | 2008-09-23 09:11:11 +0200 |
|---|---|---|
| committer | Federico Di Gregorio <fog@initd.org> | 2008-09-23 09:11:11 +0200 |
| commit | 56f6001d6df966227623351f5e8b755ee561db6a (patch) | |
| tree | 08adcc6c4a60e554e89749dbfcfae62ae18e3af3 | |
| parent | b92601306e9bf7627ee7a19382492fa4bf511d57 (diff) | |
| download | psycopg2-56f6001d6df966227623351f5e8b755ee561db6a.tar.gz | |
Support for NULLs in UUID
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | lib/extras.py | 4 | ||||
| -rw-r--r-- | tests/types_extras.py | 3 |
3 files changed, 10 insertions, 2 deletions
@@ -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 diff --git a/lib/extras.py b/lib/extras.py index 91ab9ab..67a67f2 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 94b9927..421a729 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__) |
