Skip to content

Commit

Permalink
Fix UUIDType repr (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziima authored Mar 16, 2020
1 parent 70ea53e commit e0f35fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sqlalchemy_utils/types/uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions tests/types/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e0f35fb

Please sign in to comment.