]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove "scope" keyword from scoped_session.__call__()
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 May 2017 17:00:38 +0000 (13:00 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 22 May 2017 17:00:38 +0000 (13:00 -0400)
Removed a very old keyword argument from :class:`.scoped_session`
called ``scope``.  This keyword was never documented and was an
early attempt at allowing for variable scopes.

Change-Id: I9a26498a1a66d1eafb0723e98b527688a60f9d9b
Fixes: #3796
doc/build/changelog/changelog_12.rst
doc/build/changelog/migration_12.rst
lib/sqlalchemy/orm/scoping.py
test/orm/test_scoping.py

index d8efd74a9a4ad0910a8b210385bc7382a24996ad..0f7b7b9af39869c9b7482a67fa54c09964f1d496 100644 (file)
 .. changelog::
     :version: 1.2.0b1
 
+    .. change:: 3796
+        :tags: bug, orm
+        :tickets: 3796
+
+        Removed a very old keyword argument from :class:`.scoped_session`
+        called ``scope``.  This keyword was never documented and was an
+        early attempt at allowing for variable scopes.
+
+        .. seealso::
+
+            :ref:`change_3796`
+
     .. change:: baked_opts
         :tags: feature, ext
 
index 4eec86eb9d8d1fd995352340a09668c7761c6b1a..a46311f62bd4b2f98e84a7323ebc987ff46eaee9 100644 (file)
@@ -763,6 +763,28 @@ such as :meth:`.SessionEvents.before_flush`, use the new
 
 :ticket:`3753`
 
+.. _change_3796:
+
+"scope" keyword removed from scoped_session
+-------------------------------------------
+
+A very old and undocumented keyword argument ``scope`` has been removed::
+
+    from sqlalchemy.orm import scoped_session
+    Session = scoped_session(sessionmaker())
+
+    session = Session(scope=None)
+
+The purpose of this keyword was an attempt to allow for variable
+"scopes", where ``None`` indicated "no scope" and would therefore return
+a new :class:`.Session`.   The keyword has never been documented and will
+now raise ``TypeError`` if encountered.   It is not anticipated that this
+keyword is in use, however if users report issues related to this during
+beta tesing, it can be restored with a deprecation.
+
+:ticket:`3796`
+
+
 Key Behavioral Changes - Core
 =============================
 
index 05b881320c1087792cb7d0a4fd24e99c741fc085..055ec7d6a19d38dc7dd37b5be7639dd180089c3d 100644 (file)
@@ -62,18 +62,14 @@ class scoped_session(object):
 
         """
         if kw:
-            scope = kw.pop('scope', False)
-            if scope is not None:
-                if self.registry.has():
-                    raise sa_exc.InvalidRequestError(
-                        "Scoped session is already present; "
-                        "no new arguments may be specified.")
-                else:
-                    sess = self.session_factory(**kw)
-                    self.registry.set(sess)
-                    return sess
+            if self.registry.has():
+                raise sa_exc.InvalidRequestError(
+                    "Scoped session is already present; "
+                    "no new arguments may be specified.")
             else:
-                return self.session_factory(**kw)
+                sess = self.session_factory(**kw)
+                self.registry.set(sess)
+                return sess
         else:
             return self.registry()
 
index 62247a91e6d8d538a2636ad438536bd310d1d1b7..025ad4daaf71f2f98705637af18500f2d83e33f0 100644 (file)
@@ -7,6 +7,7 @@ from sqlalchemy.testing.schema import Table, Column
 from sqlalchemy.orm import mapper, relationship, query
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import fixtures
+from sqlalchemy.testing.mock import Mock
 
 
 class _ScopedTest(fixtures.MappedTest):
@@ -93,3 +94,25 @@ class ScopedSessionTest(fixtures.MappedTest):
             "At least one scoped session is already present. ",
             Session.configure, bind=testing.db
         )
+
+    def test_call_with_kwargs(self):
+        mock_scope_func = Mock()
+        SessionMaker = sa.orm.sessionmaker()
+        Session = scoped_session(sa.orm.sessionmaker(), mock_scope_func)
+
+        s0 = SessionMaker()
+        assert s0.autocommit == False
+
+        mock_scope_func.return_value = 0
+        s1 = Session()
+        assert s1.autocommit == False
+
+        assert_raises_message(
+            sa.exc.InvalidRequestError,
+            "Scoped session is already present",
+            Session, autocommit=True
+        )
+
+        mock_scope_func.return_value = 1
+        s2 = Session(autocommit=True)
+        assert s2.autocommit == True