In my flask app, I store an instance of a user object in the session
session["user"] = user #Where user is an object
I found out that when updating the object stored in the session directly and commit, the changes are not reflected in the database.
However, I found that when updating the database object directly, the changes are reflected in the database while the session object is unchanged.
If I try a method like
user.username = username
user.password = password
db.commit() #I called my database session 'db', probably not a good idea but not the point
session["user"] = user
it throws:
sqlalchemy.orm.exc.DetachedInstanceError: Instance is not bound to a Session; attribute refresh operation cannot proceed
What could be a possible solution to update the database correctly and reflect the changes to the flask session? Thanks in advance.
flask-loginextension or just plain flask?sessionthe database session or a normal dict?