From: rallyemax Date: Tue, 21 Sep 2021 22:27:41 +0000 (-0600) Subject: Fix order of warnings filters X-Git-Tag: rel_1_4_24~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7062%2Fhead;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix order of warnings filters The `warnings.filterwarnings` method inserts entries at the front of the filter list, and entries closer to the front of the list override entries later in the list, if both match a particular warning. (See https://docs.python.org/3/library/warnings.html) The intended behavior is for all `RemovedIn20Warning` warnings to log and continue, except that specific warnings that match the defined regular expressions should be raised as exceptions. To accomplish this intent, the general filter must be inserted before the regular expression special cases. The original order would work if `warnings.filterwarnings` for the default case were invoked with `append=True`, but the intent of the documentation is for this set of filters to be determinative (i.e. to override any conflicting pre-existing filters that may exist), so `append=True` should not be used. --- diff --git a/doc/build/changelog/migration_20.rst b/doc/build/changelog/migration_20.rst index a5d90839b4..79e198d09c 100644 --- a/doc/build/changelog/migration_20.rst +++ b/doc/build/changelog/migration_20.rst @@ -260,7 +260,12 @@ the SQLAlchemy project itself, the approach taken is as follows: import warnings from sqlalchemy import exc - + + # for warnings not included in regex-based filter below, just log + warnings.filterwarnings( + "always", category=exc.RemovedIn20Warning + ) + # for warnings related to execute() / scalar(), raise for msg in [ r"The (?:Executable|Engine)\.(?:execute|scalar)\(\) function", @@ -276,11 +281,6 @@ the SQLAlchemy project itself, the approach taken is as follows: "error", message=msg, category=exc.RemovedIn20Warning, ) - # for all other warnings, just log - warnings.filterwarnings( - "always", category=exc.RemovedIn20Warning - ) - 3. As each sub-category of warnings are resolved in the application, new warnings that are caught by the "always" filter can be added to the list of "errors" to be resolved.