From d409b27a793210e975b07243ac6795fc939e7c81 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 18 Jul 2023 16:57:36 +0100 Subject: [PATCH] tests: Enable SQLAlchemy 2.0 deprecation warnings Well, sort of. We enable them but immediately filter out the ones we're actually seeing, the rationale being that we can address these in a piecemeal fashion without the risk of introducing new issues. There's a lot more to be done here. However, the work done in oslo.db [1] and other projects should provide a guide for how to resolve the outstanding issues. [1] https://review.opendev.org/q/topic:%2522sqlalchemy-20%2522+project:openstack/oslo.db Change-Id: I7a59714b104659b64f46f4c1437cfc4018356815 Signed-off-by: Stephen Finucane --- glance/tests/unit/fixtures.py | 155 ++++++++++++++++++++++++++++++++++ tox.ini | 6 +- 2 files changed, 159 insertions(+), 2 deletions(-) diff --git a/glance/tests/unit/fixtures.py b/glance/tests/unit/fixtures.py index eefd552ad0..88e729043c 100644 --- a/glance/tests/unit/fixtures.py +++ b/glance/tests/unit/fixtures.py @@ -21,7 +21,9 @@ import warnings import fixtures as pyfixtures from openstack.identity.v3 import endpoint from openstack.identity.v3 import limit as klimit +from oslo_db import warning as oslo_db_warning from oslo_limit import limit +from sqlalchemy import exc as sqla_exc _TRUE_VALUES = ('True', 'true', '1', 'yes') @@ -141,6 +143,159 @@ class WarningsFixture(pyfixtures.Fixture): warnings.filterwarnings( 'error', message="Property '.*' has moved to '.*'") + # Don't warn for our own deprecation warnings + + warnings.filterwarnings( + 'ignore', + module='glance', + category=DeprecationWarning, + ) + + # Disable deprecation warning for oslo.db's EngineFacade. We *really* + # need to get off this but it's not happening while sqlalchemy 2.0 + # stuff is ongoing + + warnings.filterwarnings( + 'ignore', + category=oslo_db_warning.OsloDBDeprecationWarning, + message='EngineFacade is deprecated', + ) + + # Enable deprecation warnings for glance itself to capture upcoming + # SQLAlchemy changes + + warnings.filterwarnings( + 'ignore', + category=sqla_exc.SADeprecationWarning, + ) + + warnings.filterwarnings( + 'error', + module='glance', + category=sqla_exc.SADeprecationWarning, + ) + + # ...but filter everything out until we get around to fixing them + # TODO(stephenfin): Fix all of these + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message=r'Invoking and_\(\) without arguments is deprecated', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message='The current statement is being autocommitted ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message='The ``aliased`` and ``from_joinpoint`` keyword ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message=r'The "whens" argument to case\(\), ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message='Using non-integer/slice indices on Row is deprecated ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message='The MetaData.bind argument is deprecated ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message=r'Passing a string to Connection.execute\(\) ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message=r'The Engine.execute\(\) method is considered legacy ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message=r'The autoload parameter is deprecated ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message=r'Query.values\(\) is deprecated ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message='The insert.values parameter will be removed ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message=r'The ``bind`` argument for schema methods ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message=r'The legacy calling style of select\(\) ', + ) + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SADeprecationWarning, + message=r'The Executable.execute\(\) method is considered legacy ', + ) + + # Enable general SQLAlchemy warnings also to ensure we're not doing + # silly stuff. It's possible that we'll need to filter things out here + # with future SQLAlchemy versions, but that's a good thing + + warnings.filterwarnings( + 'error', + module='glance', + category=sqla_exc.SAWarning, + ) + + # ...but filter everything out until we get around to fixing them + # TODO(stephenfin): Fix all of these + + warnings.filterwarnings( + 'ignore', + module='glance', + category=sqla_exc.SAWarning, + message='Class DeleteFromSelect will not make use of SQL ', + ) + self.addCleanup(self._reset_warning_filters) def _reset_warning_filters(self): diff --git a/tox.ini b/tox.ini index a17cca2ff3..cfd6a6d88e 100644 --- a/tox.ini +++ b/tox.ini @@ -6,8 +6,6 @@ skip_missing_interpreters = true [testenv] setenv = - VIRTUAL_ENV={envdir} - PYTHONWARNINGS=default::DeprecationWarning # NOTE(hemanthm): The environment variable "OS_TEST_DBAPI_ADMIN_CONNECTION" # must be set to force oslo.db tests to use a file-based sqlite database # instead of the default in-memory database, which doesn't work well with @@ -17,6 +15,8 @@ setenv = # part of its test clean-up. Think of setting this environment variable as a # clue for oslo.db to use file-based database. OS_TEST_DBAPI_ADMIN_CONNECTION=sqlite:////tmp/placeholder-never-created-nor-used.db +# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0 + SQLALCHEMY_WARN_20=1 usedevelop = True install_command = python -m pip install -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} {opts} {packages} deps = -r{toxinidir}/test-requirements.txt @@ -34,6 +34,8 @@ passenv = [testenv:functional] setenv = TEST_PATH = ./glance/tests/functional +# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0 + SQLALCHEMY_WARN_20=1 commands = stestr run {posargs} [testenv:functional-py{38,39,310,311}]