edgedb-python
edgedb-python copied to clipboard
Cannot instantiate an instance of generated Pydantic model from `gel.Object`
I am writing a custom EdgeQL query to get a User from a global, but I'm not able to actually instantiate the User pydantic model from the returned value of the query:
Query:
async def get_current_user(self) -> User | None:
result = await self.client.query_single(
"""
select (global current_user) {
id,
full_name,
email,
is_superuser,
identity: {
id,
}
}
"""
)
if result is None:
return None
return User.model_validate(dataclasses.asdict(result))
The error I get a runtime:
E pydantic_core._pydantic_core.ValidationError: 1 validation error for User
E Value error, cannot set field 'id' on User [type=value_error, input_value={'__tid__': UUID('442d005...f0-af17-c38d82281848')}}, input_type=dict]
Looks like we want a client.query_*(SomeModel, "some query") API that allows querying that unpacks into the target model directly.
we now have gel.expr() -- this should resolve this