From 60927fc03eeedf78c81a515f656e888531738e0d Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Thu, 31 Oct 2024 22:14:57 +0100 Subject: [PATCH] Mention no_autoflush in warning References: #12049 Change-Id: I057140b2fe2f5fc60d5d27a79ddf19a6196fff7b (cherry picked from commit b4fdfd489755848f4945c31f0686ad9eaf128b08) --- lib/sqlalchemy/orm/session.py | 3 ++- test/orm/test_utils.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index eb81f16e01..f18299b3ea 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -3041,7 +3041,8 @@ class Session(_SessionClassMethods, EventTarget): @util.langhelpers.tag_method_for_warnings( "This warning originated from the Session 'autoflush' process, " "which was invoked automatically in response to a user-initiated " - "operation.", + "operation. Consider using ``no_autoflush`` context manager if this " + "warning happended while initializing objects.", sa_exc.SAWarning, ) def _autoflush(self) -> None: diff --git a/test/orm/test_utils.py b/test/orm/test_utils.py index 4d6c148639..35a5060da2 100644 --- a/test/orm/test_utils.py +++ b/test/orm/test_utils.py @@ -140,7 +140,9 @@ class ContextualWarningsTest(fixtures.TestBase): + re.escape( "(This warning originated from the Session 'autoflush' " "process, which was invoked automatically in response to a " - "user-initiated operation.)" + "user-initiated operation. Consider using ``no_autoflush`` " + "context manager if this warning happended while " + "initializing objects.)" ), ): sess.execute(select(Foo)) -- 2.47.3