You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Loading an object from the database (vs init) produces different field types - it shouldn't #110
changed the title [-]When loading an object from the database, the fields should be loaded according to their type[/-][+]Loading an object from the database (vs init) produces different field types - it shouldn't[/+]on Sep 23, 2021
Essentially what I do is create a custom string loader sqlalchemy type that instantiates the value after loading from the db (have the same for other base types), and I just force its usage here.
Activity
[-]When loading an object from the database, the fields should be loaded according to their type[/-][+]Loading an object from the database (vs init) produces different field types - it shouldn't[/+]jack-michaud commentedon Oct 7, 2021
What is the type of
foo.barwhen you load it from the database?tasn commentedon Oct 7, 2021
strYou can check out https://github.com/tiangolo/sqlmodel/blob/main/sqlmodel/main.py#L372 to see exactly what's going on.
To workaround this issue, I have a fork (which is what we use) that lets you customize the type in a few ways, this is one of them: https://github.com/tasn/sqlmodel/blob/fixes/sqlmodel/main.py#L378
Essentially what I do is create a custom string loader sqlalchemy type that instantiates the value after loading from the db (have the same for other base types), and I just force its usage here.
jp-u commentedon Mar 10, 2024
This is still an issue on data returned from the database, seemingly for fields that use anything other than builtins.