pony
pony copied to clipboard
PonyOrm not work with UUID as PK
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
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"')
(((
default
requires a function, so your Entity's first line should read:
id = orm.PrimaryKey(uuid.UUID, default=uuid.uuid4)