pony icon indicating copy to clipboard operation
pony copied to clipboard

PonyOrm not work with UUID as PK

Open Evgeniy-Polyak opened this issue 1 year ago • 2 comments

I have next entity:

class SchemaEntity(db.Entity):
    id = orm.PrimaryKey(uuid.UUID, default=uuid.uuid4())
    source_name = orm.Required(str)
    target_name = orm.Required(str)

I try do next query:

entity = SchemaEntity[uuid.UUID('0e325a58-3445-4354-841b-56f586c69b1c')]

result => pony.orm.core.ObjectNotFound: SchemaEntity[UUID('0e325a58-3445-4354-841b-56f586c69b1c')]

but i have success result for SQL: select * from schema_ksunci_entity where id = '0e325a58-3445-4354-841b-56f586c69b1c'

!wherwith

i have success result for SchemaEntity.select()[:] query

P.S. Python 3.10.5 Pony 0.7.16

Evgeniy-Polyak avatar Aug 23 '22 12:08 Evgeniy-Polyak

It is work only with select by sql

entity = SchemaEntity.select_by_sql('select * from schema_ksunci_entity where id = "0e325a58-3445-4354-841b-56f586c69b1c"')

(((

Evgeniy-Polyak avatar Aug 23 '22 12:08 Evgeniy-Polyak

default requires a function, so your Entity's first line should read:

id = orm.PrimaryKey(uuid.UUID, default=uuid.uuid4)

LaundroMat avatar Aug 26 '22 18:08 LaundroMat