edgedb-python icon indicating copy to clipboard operation
edgedb-python copied to clipboard

Cannot instantiate an instance of generated Pydantic model from `gel.Object`

Open scotttrinh opened this issue 5 months ago • 1 comments

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]

scotttrinh avatar Jun 18 '25 15:06 scotttrinh

Looks like we want a client.query_*(SomeModel, "some query") API that allows querying that unpacks into the target model directly.

scotttrinh avatar Jun 18 '25 17:06 scotttrinh

we now have gel.expr() -- this should resolve this

1st1 avatar Jul 12 '25 05:07 1st1