]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove depractions:
authorFederico Caselli <cfederico87@gmail.com>
Sun, 24 Oct 2021 16:53:54 +0000 (18:53 +0200)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 26 Oct 2021 18:44:30 +0000 (14:44 -0400)
- Passing bind arguments to Session.execute
- This Session located a target engine via bound metadata

Change-Id: I916c8c4cff344ee5652fceac4dfd241dd8160f7b

lib/sqlalchemy/testing/warnings.py
test/ext/test_horizontal_shard.py
test/orm/declarative/test_deprecations.py
test/orm/test_deprecations.py
test/orm/test_manytomany.py
test/orm/test_unitofwork.py

index 9e02a0c03bdbd690a9be66a3d37bd346342ac63c..a50b78294cb0eb694a341128d486e44d84074725 100644 (file)
@@ -86,11 +86,9 @@ def setup_filters():
         #
         # ORM Session
         #
-        r"This Session located a target engine via bound metadata",
         r"The Session.autocommit parameter is deprecated ",
         r".*object is being merged into a Session along the backref "
         "cascade path",
-        r"Passing bind arguments to Session.execute\(\) as keyword arguments",
         r"The merge_result\(\) method is superseded by the "
         r"merge_frozen_result\(\)",
         r"The Session.begin.subtransactions flag is deprecated",
index a0bc8bbe5498ce30fa53d9b955ced3311fcfa354..460bdd6c3fcd8606598173d1c70c2d66d19a1129 100644 (file)
@@ -260,7 +260,8 @@ class ShardTest(object):
         sess = self._fixture_data()
         eq_(
             sess.execute(
-                weather_locations.select(), shard_id="asia"
+                weather_locations.select(),
+                bind_arguments=dict(shard_id="asia"),
             ).fetchall(),
             [(1, "Asia", "Tokyo")],
         )
index e3015f6435587e4a0d4dc30976e8138cd8709025..7267a9aa22b212c72aea21b46b5536bb3db63870 100644 (file)
@@ -21,7 +21,10 @@ class BoundMetadataDeclarativeTest(fixtures.MappedTest):
 
         s = Session()
 
-        is_(s.get_bind(User), testing.db)
+        with testing.expect_deprecated_20(
+            "This Session located a target engine via bound metadata"
+        ):
+            is_(s.get_bind(User), testing.db)
 
     def test_bound_cls_registry_base(self):
         reg = registry(_bind=testing.db)
@@ -33,8 +36,10 @@ class BoundMetadataDeclarativeTest(fixtures.MappedTest):
             id = Column(Integer, primary_key=True)
 
         s = Session()
-
-        is_(s.get_bind(User), testing.db)
+        with testing.expect_deprecated_20(
+            "This Session located a target engine via bound metadata"
+        ):
+            is_(s.get_bind(User), testing.db)
 
     def test_bound_cls_registry_decorated(self):
         reg = registry(_bind=testing.db)
@@ -46,4 +51,7 @@ class BoundMetadataDeclarativeTest(fixtures.MappedTest):
 
         s = Session()
 
-        is_(s.get_bind(User), testing.db)
+        with testing.expect_deprecated_20(
+            "This Session located a target engine via bound metadata"
+        ):
+            is_(s.get_bind(User), testing.db)
index ddfad7e0f0d47dd9e5e96119d9040abb21a1e0fb..d2094b7acd09f332abc6bed86b2f83025e56ae43 100644 (file)
@@ -5707,13 +5707,19 @@ class GetBindTest(_GetBindTest):
 
     def test_fallback_table_metadata(self):
         session = self._fixture({})
-        is_(session.get_bind(self.classes.BaseClass), testing.db)
+        with testing.expect_deprecated_20(
+            "This Session located a target engine via bound metadata"
+        ):
+            is_(session.get_bind(self.classes.BaseClass), testing.db)
 
     def test_bind_base_table_concrete_sub_class(self):
         base_class_bind = Mock()
         session = self._fixture({self.tables.base_table: base_class_bind})
 
-        is_(session.get_bind(self.classes.ConcreteSubClass), testing.db)
+        with testing.expect_deprecated_20(
+            "This Session located a target engine via bound metadata"
+        ):
+            is_(session.get_bind(self.classes.ConcreteSubClass), testing.db)
 
 
 class DeprecationScopedSessionTest(fixtures.MappedTest):
index 32dfe3af4ecdc780a81f4d9ef8af0a3640182340..1abf5551a5eb8296cb72b824f5d5347512323590 100644 (file)
@@ -385,7 +385,7 @@ class M2MTest(fixtures.MappedTest):
         p1.place_id
         p1.transitions
 
-        sess.execute(place_input.delete(), mapper=Place)
+        sess.execute(place_input.delete())
         p1.place_id = 7
 
         assert_raises_message(
@@ -398,7 +398,7 @@ class M2MTest(fixtures.MappedTest):
 
         p1.place_id
         p1.transitions
-        sess.execute(place_input.delete(), mapper=Place)
+        sess.execute(place_input.delete())
         p1.transitions.remove(t1)
         assert_raises_message(
             orm_exc.StaleDataError,
index afba9d95324271fd74928df72a39549e48c03f36..e547e01d99dbe3bb8eb3e39520454557f17c870a 100644 (file)
@@ -2022,7 +2022,7 @@ class SaveTest(_fixtures.FixtureTest):
         session.commit()
 
         eq_(
-            list(session.execute(orders.select(), mapper=Order)),
+            list(session.execute(orders.select())),
             [(42, None, None, "foo", None)],
         )
         session.expunge_all()
@@ -2037,7 +2037,11 @@ class SaveTest(_fixtures.FixtureTest):
         session.flush()
 
         eq_(
-            list(session.execute(orders.select(), mapper=Order)),
+            list(
+                session.execute(
+                    orders.select(),
+                )
+            ),
             [(42, None, None, "hoho", None)],
         )
 
@@ -2048,7 +2052,11 @@ class SaveTest(_fixtures.FixtureTest):
         o.description = None
         session.flush()
         eq_(
-            list(session.execute(orders.select(), mapper=Order)),
+            list(
+                session.execute(
+                    orders.select(),
+                )
+            ),
             [(42, None, None, None, None)],
         )
         session.close()
@@ -2216,7 +2224,7 @@ class SaveTest(_fixtures.FixtureTest):
         session.flush()
 
         # test insert ordering is maintained
-        assert names == ["user1", "user2", "user4", "user5", "user3"]
+        eq_(names, ["user1", "user2", "user4", "user5", "user3"])
         session.expunge_all()
 
         sa.orm.clear_mappers()
@@ -2744,7 +2752,7 @@ class ManyToManyTest(_fixtures.FixtureTest):
 
         session.expunge_all()
         item = session.query(Item).get(item.id)
-        assert item.keywords == [k1, k2]
+        eq_(item.keywords, [k1, k2])
 
     def test_association(self):
         """Basic test of an association object"""
@@ -3141,9 +3149,20 @@ class RowSwitchTest(fixtures.MappedTest):
         sess.add(o5)
         sess.flush()
 
-        eq_(list(sess.execute(t5.select(), mapper=T5)), [(1, "some t5")])
         eq_(
-            list(sess.execute(t6.select().order_by(t6.c.id), mapper=T5)),
+            list(
+                sess.execute(
+                    t5.select(),
+                )
+            ),
+            [(1, "some t5")],
+        )
+        eq_(
+            list(
+                sess.execute(
+                    t6.select().order_by(t6.c.id),
+                )
+            ),
             [(1, "some t6", 1), (2, "some other t6", 1)],
         )
 
@@ -3156,9 +3175,20 @@ class RowSwitchTest(fixtures.MappedTest):
         sess.add(o6)
         sess.flush()
 
-        eq_(list(sess.execute(t5.select(), mapper=T5)), [(1, "some other t5")])
         eq_(
-            list(sess.execute(t6.select().order_by(t6.c.id), mapper=T5)),
+            list(
+                sess.execute(
+                    t5.select(),
+                )
+            ),
+            [(1, "some other t5")],
+        )
+        eq_(
+            list(
+                sess.execute(
+                    t6.select().order_by(t6.c.id),
+                )
+            ),
             [(3, "third t6", 1), (4, "fourth t6", 1)],
         )
 
@@ -3189,14 +3219,33 @@ class RowSwitchTest(fixtures.MappedTest):
         sess.add(o5)
         sess.flush()
 
-        assert list(sess.execute(t5.select(), mapper=T5)) == [(1, "some t5")]
-        assert testing.rowset(sess.execute(t5t7.select(), mapper=T5)) == set(
-            [(1, 1), (1, 2)]
+        eq_(
+            list(
+                sess.execute(
+                    t5.select(),
+                )
+            ),
+            [(1, "some t5")],
+        )
+        eq_(
+            testing.rowset(
+                sess.execute(
+                    t5t7.select(),
+                )
+            ),
+            set([(1, 1), (1, 2)]),
+        )
+        eq_(
+            list(
+                sess.execute(
+                    t7.select(),
+                )
+            ),
+            [
+                (1, "some t7"),
+                (2, "some other t7"),
+            ],
         )
-        assert list(sess.execute(t7.select(), mapper=T5)) == [
-            (1, "some t7"),
-            (2, "some other t7"),
-        ]
 
         o6 = T5(
             data="some other t5",
@@ -3212,13 +3261,25 @@ class RowSwitchTest(fixtures.MappedTest):
         sess.add(o6)
         sess.flush()
 
-        assert list(sess.execute(t5.select(), mapper=T5)) == [
-            (1, "some other t5")
-        ]
-        assert list(sess.execute(t7.select(), mapper=T5)) == [
-            (3, "third t7"),
-            (4, "fourth t7"),
-        ]
+        eq_(
+            list(
+                sess.execute(
+                    t5.select(),
+                )
+            ),
+            [(1, "some other t5")],
+        )
+        eq_(
+            list(
+                sess.execute(
+                    t7.select(),
+                )
+            ),
+            [
+                (3, "third t7"),
+                (4, "fourth t7"),
+            ],
+        )
 
     def test_manytoone(self):
         t6, T6, t5, T5 = (
@@ -3241,10 +3302,22 @@ class RowSwitchTest(fixtures.MappedTest):
         sess.add(o5)
         sess.flush()
 
-        assert list(sess.execute(t5.select(), mapper=T5)) == [(1, "some t5")]
-        assert list(sess.execute(t6.select(), mapper=T5)) == [
-            (1, "some t6", 1)
-        ]
+        eq_(
+            list(
+                sess.execute(
+                    t5.select(),
+                )
+            ),
+            [(1, "some t5")],
+        )
+        eq_(
+            list(
+                sess.execute(
+                    t6.select(),
+                )
+            ),
+            [(1, "some t6", 1)],
+        )
 
         o6 = T6(data="some other t6", id=1, t5=T5(data="some other t5", id=2))
         sess.delete(o5)
@@ -3252,12 +3325,22 @@ class RowSwitchTest(fixtures.MappedTest):
         sess.add(o6)
         sess.flush()
 
-        assert list(sess.execute(t5.select(), mapper=T5)) == [
-            (2, "some other t5")
-        ]
-        assert list(sess.execute(t6.select(), mapper=T5)) == [
-            (1, "some other t6", 2)
-        ]
+        eq_(
+            list(
+                sess.execute(
+                    t5.select(),
+                )
+            ),
+            [(2, "some other t5")],
+        )
+        eq_(
+            list(
+                sess.execute(
+                    t6.select(),
+                )
+            ),
+            [(1, "some other t6", 2)],
+        )
 
 
 class InheritingRowSwitchTest(fixtures.MappedTest):