From: Federico Caselli Date: Thu, 31 Oct 2024 21:14:57 +0000 (+0100) Subject: Mention no_autoflush in warning X-Git-Tag: rel_2_0_37~34^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=60927fc03eeedf78c81a515f656e888531738e0d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Mention no_autoflush in warning References: #12049 Change-Id: I057140b2fe2f5fc60d5d27a79ddf19a6196fff7b (cherry picked from commit b4fdfd489755848f4945c31f0686ad9eaf128b08) --- 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))