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
Calculated columns not working (sqlaquemy.orm.column_property) #240
Create all tables and it will raise the sqlalquemy.exc.InvalidRequestError
sqlalchemy.exc.InvalidRequestError: When initializing mapper mapped class Hero->hero, expression 'Team' failed to locate a name ('Team').
If this is a class name, consider adding this relationship() to the <class '__main__.Hero'> class after both dependent classes have been defined.
the order_number column is NOT getting created in my table.
That's the whole idea of column_property, to have something appear in the objects, which is not in the db, but computed from values in the db. Like in SQLAlchemy's example:
Activity
byrman commentedon Feb 12, 2022
Is assigning the property after the class definition instead of inline a workaround?
stuartaccent commentedon Mar 12, 2022
As a workaround. Am pretty new to this lib so sorry if its not very good of a solution. Dont know of the impacts this has.
This will work for an internal value that doesnt go out in the api response.
Then you can define a response_model like so and just return the instance:
Response
{ "start": "2022-03-11T16:14:42.413349", "end": "2022-03-11T16:19:06.093423", "difference": 263.680074 }strobelo commentedon Mar 26, 2022
northtree commentedon Apr 13, 2022
@angel-langdon did you manage to have
column_propertyfrom select?deZakelijke commentedon Apr 14, 2022
This looks exactly like what I need but when I tried this I got the error
Cannot compile Column object until its 'name' is assigned.strobelo commentedon Jul 9, 2022
I was able to resolve this by explicitly specifying the
sa_columnattribute in any model's fields that thecolumn_propertyreferences:gives
Cannot compile Column object until its 'name' is assigned., whereasworks.
nagraj98 commentedon Jun 7, 2023
I was so happy to see this solution and even happier when it didn't throw any errors ! But my happiness was shortlived...
Below is my class (its rather simple!) but the order_number column is NOT getting created in my table.
Am I missing something peeps ?
antont commentedon Jun 8, 2023
That's the whole idea of
column_property, to have something appear in the objects, which is not in the db, but computed from values in the db. Like in SQLAlchemy's example:https://docs.sqlalchemy.org/en/20/orm/mapped_sql_expr.html#using-column-property
samidarko commentedon Feb 3, 2024
This worked for me
Update, this is working:
50Bytes-dev commentedon Mar 1, 2024
Use my PR #801
Kusmeroglu commentedon Apr 24, 2024
Another way to work around this: