From 444cec2ba04d12980b116086b727c7ff40db63f4 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Sat, 18 Feb 2023 14:50:58 +0100 Subject: [PATCH] [sqlalchemy-20] Use Connection.execute() instead of Engine.execute() According to the SLQAlchemy documentation, "the Engine.execute() method is considered legacy as of the 1.x series of SQLAlchemy and will be removed in 2.0. All statement execution in SQLAlchemy 2.0 is performed by the Connection.execute() method of Connection, or in the ORM by the Session.execute() method of Session." Change-Id: Ic4d7a0740f7136cac2055e57e57f66e76cb150f3 Closes-Bug: #2008223 --- neutron_lib/fixture.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/neutron_lib/fixture.py b/neutron_lib/fixture.py index 217dd27c9..13191d882 100644 --- a/neutron_lib/fixture.py +++ b/neutron_lib/fixture.py @@ -100,13 +100,10 @@ class _EnableSQLiteFKsFixture(fixtures.Fixture): def _setUp(self): if self.engine.name == 'sqlite': - self.engine.execute("PRAGMA foreign_keys=ON") - - def disable_fks(): - with self.engine.connect() as conn: - conn.connection.rollback() - conn.execute("PRAGMA foreign_keys=OFF") - self.addCleanup(disable_fks) + with self.engine.connect() as conn: + cursor = conn.connection.cursor() + cursor.execute('PRAGMA foreign_keys=ON') + cursor.close() class SqlFixture(fixtures.Fixture):