diff options
author | Sean McGinnis <sean.mcginnis@gmail.com> | 2019-04-09 16:49:11 -0500 |
---|---|---|
committer | Stephen Finucane <stephenfin@redhat.com> | 2019-04-11 11:03:59 +0000 |
commit | 3c50cb5cce82101a7be491ea24a713d70ca064e3 (patch) | |
tree | d63ff14ade40f72dfda48d97603f0802a53dbe68 /oslo_db | |
parent | 57333e902a3747715b2f13ea63477cc4aedc2129 (diff) | |
download | oslo-db-3c50cb5cce82101a7be491ea24a713d70ca064e3.tar.gz |
Fix deprecation warnings under py36
This addresses two sources of deprecation warnings.
The collections package has moved ABC classes under collections.abc. Six
does not support this move yet, so this updates the code to try to
import from the newer locations, and if that fails, import from the old
location.
Py36 is also more strict about escape sequences in strings. This happens
move often with regex strings that are valid regex but not a valid
normal string escape sequence. This addresses those errors by switching
to raw strings.
Change-Id: I4c61df6b6432b135297f38c02b4538e4ba56be51
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
Diffstat (limited to 'oslo_db')
-rw-r--r-- | oslo_db/sqlalchemy/exc_filters.py | 19 | ||||
-rw-r--r-- | oslo_db/sqlalchemy/utils.py | 9 | ||||
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_models.py | 9 |
3 files changed, 24 insertions, 13 deletions
diff --git a/oslo_db/sqlalchemy/exc_filters.py b/oslo_db/sqlalchemy/exc_filters.py index 0144826..637667b 100644 --- a/oslo_db/sqlalchemy/exc_filters.py +++ b/oslo_db/sqlalchemy/exc_filters.py @@ -195,15 +195,16 @@ def _sqlite_dupe_key_error(integrity_error, match, engine_name, is_disconnect): r"(?i).*foreign key constraint failed") @filters("postgresql", sqla_exc.IntegrityError, r".*on table \"(?P<table>[^\"]+)\" violates " - "foreign key constraint \"(?P<constraint>[^\"]+)\".*\n" - "DETAIL: Key \((?P<key>.+)\)=\(.+\) " - "is (not present in|still referenced from) table " - "\"(?P<key_table>[^\"]+)\".") -@filters("mysql", sqla_exc.IntegrityError, - r".*Cannot (add|delete) or update a (child|parent) row: " - 'a foreign key constraint fails \([`"].+[`"]\.[`"](?P<table>.+)[`"], ' - 'CONSTRAINT [`"](?P<constraint>.+)[`"] FOREIGN KEY ' - '\([`"](?P<key>.+)[`"]\) REFERENCES [`"](?P<key_table>.+)[`"] ') + r"foreign key constraint \"(?P<constraint>[^\"]+)\".*\n" + r"DETAIL: Key \((?P<key>.+)\)=\(.+\) " + r"is (not present in|still referenced from) table " + r"\"(?P<key_table>[^\"]+)\".") +@filters( + "mysql", sqla_exc.IntegrityError, + r".*Cannot (add|delete) or update a (child|parent) row: " + r'a foreign key constraint fails \([`"].+[`"]\.[`"](?P<table>.+)[`"], ' + r'CONSTRAINT [`"](?P<constraint>.+)[`"] FOREIGN KEY ' + r'\([`"](?P<key>.+)[`"]\) REFERENCES [`"](?P<key_table>.+)[`"] ') def _foreign_key_error(integrity_error, match, engine_name, is_disconnect): """Filter for foreign key errors.""" diff --git a/oslo_db/sqlalchemy/utils.py b/oslo_db/sqlalchemy/utils.py index 34d26de..b54774d 100644 --- a/oslo_db/sqlalchemy/utils.py +++ b/oslo_db/sqlalchemy/utils.py @@ -17,6 +17,12 @@ # under the License. import collections +# TODO(smcginnis) update this once six has support for collections.abc +# (https://github.com/benjaminp/six/pull/241) or clean up once we drop py2.7. +try: + from collections.abc import Iterable +except ImportError: + from collections import Iterable import contextlib import inspect as pyinspect import itertools @@ -280,8 +286,7 @@ def paginate_query(query, model, limit, sort_keys, marker=None, def to_list(x, default=None): if x is None: return default - if not isinstance(x, collections.Iterable) or \ - isinstance(x, six.string_types): + if not isinstance(x, Iterable) or isinstance(x, six.string_types): return [x] elif isinstance(x, list): return x diff --git a/oslo_db/tests/sqlalchemy/test_models.py b/oslo_db/tests/sqlalchemy/test_models.py index 540f4f8..302a994 100644 --- a/oslo_db/tests/sqlalchemy/test_models.py +++ b/oslo_db/tests/sqlalchemy/test_models.py @@ -13,7 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. -import collections +# TODO(smcginnis) update this once six has support for collections.abc +# (https://github.com/benjaminp/six/pull/241) or clean up once we drop py2.7. +try: + from collections.abc import Iterable +except ImportError: + from collections import Iterable import datetime import mock @@ -51,7 +56,7 @@ class ModelBaseTest(test_base._DbTestCase): "Method %s() is not found" % method) def test_modelbase_is_iterable(self): - self.assertTrue(issubclass(models.ModelBase, collections.Iterable)) + self.assertTrue(issubclass(models.ModelBase, Iterable)) def test_modelbase_set(self): self.mb['world'] = 'hello' |