From e0f35fbc5b80c9126ebd22c78cf5b5d75ddc4e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlastimil=20Z=C3=ADma?= Date: Mon, 16 Mar 2020 12:55:23 +0100 Subject: [PATCH] Fix UUIDType repr (#424) --- sqlalchemy_utils/types/uuid.py | 5 ++++- tests/types/test_uuid.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sqlalchemy_utils/types/uuid.py b/sqlalchemy_utils/types/uuid.py index 2d4143e2..8a7721e4 100644 --- a/sqlalchemy_utils/types/uuid.py +++ b/sqlalchemy_utils/types/uuid.py @@ -2,7 +2,7 @@ import uuid -from sqlalchemy import types +from sqlalchemy import types, util from sqlalchemy.dialects import mssql, postgresql from .scalar_coercible import ScalarCoercible @@ -35,6 +35,9 @@ def __init__(self, binary=True, native=True): self.binary = binary self.native = native + def __repr__(self): + return util.generic_repr(self) + def load_dialect_impl(self, dialect): if dialect.name == 'postgresql' and self.native: # Use the native UUID type. diff --git a/tests/types/test_uuid.py b/tests/types/test_uuid.py index 4ef79016..17fb5649 100644 --- a/tests/types/test_uuid.py +++ b/tests/types/test_uuid.py @@ -24,6 +24,16 @@ def init_models(User): class TestUUIDType(object): + def test_repr(self): + plain = UUIDType() + assert repr(plain) == 'UUIDType()' + + text = UUIDType(binary=False) + assert repr(text) == 'UUIDType(binary=False)' + + not_native = UUIDType(native=False) + assert repr(not_native) == 'UUIDType(native=False)' + def test_commit(self, session, User): obj = User() obj.id = uuid.uuid4().hex