I'm fetching some objects from database using SQL Alchemy. Because I'm using the objects in Flask and Jinja to create web pages for the user, it's sometimes convenient to edit raw database values. This could mean swapping user id's for legible user names, for example.
When I do this to the model objects returned by my database function (see example below), I start getting errors. I suspect this has to do with the fact that SQLAlchemy 'thinks' that I want to alter database rows because I am editing attributes of the Model class/object.
However, I only want to use them as 'flat' data-only objects, for this case. What is the best way to circumvent this problem?
if not sql_session.query(Client).count():
return {"state" : False, "clients" : [] }
else:
return {"state" : True, "clients" : sql_session.query(Client).filter().all() }