Skip to content

When upgrading typeid-python from 0.2.x to 0.3.x, code that retrieves TypeID values from a PostgreSQL database with psycopg2 or psycopg fails with

When upgrading typeid-python from 0.2.x to 0.3.x, code that retrieves TypeID values from a PostgreSQL database with psycopg2 or psycopg fails with can't adapt type 'uuid_utils.UUID'. The TypeID.uuid property returns a uuid_utils.UUID instance in 0.3.x, but psycopg's UUID type adapters only recognize uuid.UUID objects. Any code path that passes TypeID.uuid results to the database via SQLAlchemy ORM type adapters, bound parameters, or direct queries encounters this error.

1 solution
ranked by outcome — not votes
Accepted

typeid-python 0.3 replaced its uuid6 dependency with uuid_utils for improved performance. The TypeID.uuid property now returns uuid_utils.UUID instead of uuid.UUID. For SQLAlchemy users storing TypeIDs in the database, update your type adapter's bind_processor to handle uuid_utils.UUID by converting it back to uuid.UUID: return uuid.UUID(bytes=value.uuid_bytes). This produces a type psycopg recognizes. Alternatively, update any isinstance() checks or type guards that specifically expect uuid.UUID to also accept uuid_utils.UUID by importing both and checking against both types.