From 769d462b3970c254dbaa937fa55105e1a6ce6e4f Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Sat, 14 Sep 2024 20:17:49 +0200 Subject: [PATCH] fix: missing no_autoflush prevents users imports * without the no_autoflush the first() method call initiates a autoflush which calls the session.flush() method. this flushes the models in the session. this prevents then that other packages could use the pre_commit hook to collect all not flushed models and possible index them. --- flask_security/datastore.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/flask_security/datastore.py b/flask_security/datastore.py index 4d16d140..f907e544 100644 --- a/flask_security/datastore.py +++ b/flask_security/datastore.py @@ -201,9 +201,10 @@ def get_user_by_email(self, identifier): for attr in get_identity_attributes(): query = alchemyFn.lower(getattr(self.user_model, attr)) \ == alchemyFn.lower(identifier) - rv = self.user_model.query.filter(query).first() - if rv is not None: - return rv + with self.db.session.no_autoflush: + rv = self.user_model.query.filter(query).first() + if rv is not None: + return rv def get_user_by_id(self, identifier): return self.user_model.query.get(identifier)