From c1c2b40b38c9c53d7bbed3d45f8777c9948b55bc Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Fri, 10 Jul 2015 14:51:25 +0900 Subject: [PATCH] Some drivers convert pg uuid to UUID by themselves --- sqlalchemy_utils/types/uuid.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sqlalchemy_utils/types/uuid.py b/sqlalchemy_utils/types/uuid.py index 2fc3ad1..d464cdf 100644 --- a/sqlalchemy_utils/types/uuid.py +++ b/sqlalchemy_utils/types/uuid.py @@ -73,6 +73,10 @@ class UUIDType(types.TypeDecorator, ScalarCoercible): return value if self.native and dialect.name == 'postgresql': + if isinstance(value, uuid.UUID): + # Some drivers convert PostgreSQL's uuid values to + # Python's uuid.UUID objects by themselves + return value return uuid.UUID(value) return uuid.UUID(bytes=value) if self.binary else uuid.UUID(value)