New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new type to be able to return UUID types as JSON #897

Open
jsabater opened this Issue Oct 27, 2018 · 0 comments

Comments

1 participant
@jsabater
Copy link

jsabater commented Oct 27, 2018

When using SQLAlchemy over PostgreSQL, if there is a native UUID type you want returned as part of the payload and the output format is JSON, you get this error:

TypeError: UUID('fea602c9-bc4d-432a-ad57-74d88416c04b') is not JSON serializable

This ticket is to request the addition of a new type to the list of existing ones so that UUIDs can be either cast to str or its hexadecimal representation used instead. Excerpt of code of the SQLAlchemy class used when this was tested:

from uuid import uuid4
from sqlalchemy.dialects.postgresql import UUID
[..]
class Booking(Base):
    __tablename__ = 'booking'
    [..]
    uuid = Column(UUID(as_uuid=True), nullable=False, index=True, unique=True,
        server_default=text('uuid_generate_v4()'),
        default=uuid4,
        comment='Unique code used to test Zato')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment