diff options
Diffstat (limited to 'oslo_db')
-rw-r--r-- | oslo_db/sqlalchemy/enginefacade.py | 6 | ||||
-rw-r--r-- | oslo_db/sqlalchemy/update_match.py | 6 | ||||
-rw-r--r-- | oslo_db/sqlalchemy/utils.py | 10 |
3 files changed, 14 insertions, 8 deletions
diff --git a/oslo_db/sqlalchemy/enginefacade.py b/oslo_db/sqlalchemy/enginefacade.py index 7871258..80c320b 100644 --- a/oslo_db/sqlalchemy/enginefacade.py +++ b/oslo_db/sqlalchemy/enginefacade.py @@ -843,7 +843,8 @@ class _TransactionContextManager(object): new = self._clone() new._root = new new._root_factory = self._root_factory._create_factory_copy() - assert not new._factory._started + if new._factory._started: + raise AssertionError('TransactionFactory is already started') return new def patch_factory(self, factory_or_manager): @@ -869,7 +870,8 @@ class _TransactionContextManager(object): raise ValueError( "_TransactionContextManager or " "_TransactionFactory expected.") - assert self._root is self + if self._root is not self: + raise AssertionError('patch_factory only works for root factory.') existing_factory = self._root_factory self._root_factory = factory diff --git a/oslo_db/sqlalchemy/update_match.py b/oslo_db/sqlalchemy/update_match.py index 5765817..543101e 100644 --- a/oslo_db/sqlalchemy/update_match.py +++ b/oslo_db/sqlalchemy/update_match.py @@ -164,9 +164,9 @@ def update_on_match( entity = inspect(specimen) mapper = entity.mapper - assert \ - [desc['type'] for desc in query.column_descriptions] == \ - [mapper.class_], "Query does not match given specimen" + if [desc['type'] for desc in query.column_descriptions] != \ + [mapper.class_]: + raise AssertionError("Query does not match given specimen") criteria = manufacture_entity_criteria( specimen, include_only=include_only, exclude=[surrogate_key]) diff --git a/oslo_db/sqlalchemy/utils.py b/oslo_db/sqlalchemy/utils.py index 7c5f22c..34d26de 100644 --- a/oslo_db/sqlalchemy/utils.py +++ b/oslo_db/sqlalchemy/utils.py @@ -181,7 +181,9 @@ def paginate_query(query, model, limit, sort_keys, marker=None, LOG.warning('Unique keys not in sort_keys. ' 'The sorting order may be unstable.') - assert(not (sort_dir and sort_dirs)) + if sort_dir and sort_dirs: + raise AssertionError('Disallow set sort_dir and ' + 'sort_dirs at the same time.') # Default the sort direction to ascending if sort_dirs is None and sort_dir is None: @@ -191,7 +193,8 @@ def paginate_query(query, model, limit, sort_keys, marker=None, if sort_dirs is None: sort_dirs = [sort_dir for _sort_key in sort_keys] - assert(len(sort_dirs) == len(sort_keys)) + if len(sort_dirs) != len(sort_keys): + raise AssertionError('sort_dirs and sort_keys must have same length.') # Add sorting for current_sort_key, current_sort_dir in zip(sort_keys, sort_dirs): @@ -1152,7 +1155,8 @@ def suspend_fk_constraints_for_col_alter( fks = [] for ref_table_name in referents: for fk in insp.get_foreign_keys(ref_table_name): - assert fk.get('name') + if not fk.get('name'): + raise AssertionError("foreign key hasn't a name.") if fk['referred_table'] == table_name and \ column_name in fk['referred_columns']: fk['source_table'] = ref_table_name |