Flask-User icon indicating copy to clipboard operation
Flask-User copied to clipboard

Question why SQLDbAdapter.save_object() does pass?

Open immunochomik opened this issue 6 years ago • 2 comments

I have found that when I am trying to confirm email, then UserManager__Views.confirm_email_view calls self.db_manager.save_user_and_user_email(user, user_email) witch in turns calls self.db_adapter.save_object(user) and this does nothing silently. It is very confusing behaviour and it results in the user not having 'email_confirmed_at' updated. And I do not see any sensible way of overwriting the SQLDbAdapter.save_object() that is used. I am probably miss configuring something here.

immunochomik avatar Oct 09 '18 05:10 immunochomik

SQLAlchemy uses DB sessions to commit changes to the DB, while other ORMs use object.save().

DbAdapter needs to support either approaches, so it has a object_save() method and a commit() method.

In the SQLDbAdapter implementation, the db_adapter.object_save() does nothing, and the db_adapter.commit() calls SQLAlchemy's db.session.commit().

Perhaps the code is missing a call to db_adapter.commit()???

lingthio avatar Oct 09 '18 06:10 lingthio

Thank you for your prompt answer, Grate Work !!! Ok I have found it :). I understand now that SQLAlchemy objects do not have save on them as this is not ActiveRecord. My problem was caused by the fact that I have had twice call db = flask_sqlalchemy.SQLAlchemy() in my code, once in main innit script and once in model definition module. And due to that sqlalchemy.util._collections.ScopedRegistry.__call__, was geting KeyError and creating new session and this one did not contain the changes so updates were impossible. That was one hard thing to find :/

immunochomik avatar Oct 10 '18 06:10 immunochomik