Python oslo_db.exception.InvalidSortKey() Examples
The following are 11
code examples of oslo_db.exception.InvalidSortKey().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_db.exception
, or try the search function
.
Example #1
Source File: api.py From zun with Apache License 2.0 | 5 votes |
def _paginate_query(model, limit=None, marker=None, sort_key=None, sort_dir=None, query=None, default_sort_key='id'): if not query: query = model_query(model) sort_keys = [default_sort_key] if sort_key and sort_key not in sort_keys: sort_keys.insert(0, sort_key) try: query = db_utils.paginate_query(query, model, limit, sort_keys, marker=marker, sort_dir=sort_dir) except db_exc.InvalidSortKey: raise exception.InvalidParameterValue( _('The sort_key value "%(key)s" is an invalid field for sorting') % {'key': sort_key}) return query.all()
Example #2
Source File: api.py From magnum with Apache License 2.0 | 5 votes |
def _paginate_query(model, limit=None, marker=None, sort_key=None, sort_dir=None, query=None): if not query: query = model_query(model) sort_keys = ['id'] if sort_key and sort_key not in sort_keys: sort_keys.insert(0, sort_key) try: query = db_utils.paginate_query(query, model, limit, sort_keys, marker=marker, sort_dir=sort_dir) except db_exc.InvalidSortKey: raise exception.InvalidParameterValue( _('The sort_key value "%(key)s" is an invalid field for sorting') % {'key': sort_key}) return query.all()
Example #3
Source File: api.py From masakari with Apache License 2.0 | 5 votes |
def failover_segment_get_all_by_filters( context, filters=None, sort_keys=None, sort_dirs=None, limit=None, marker=None): # NOTE(Dinesh_Bhor): If the limit is 0 there is no point in even going # to the database since nothing is going to be returned anyway. if limit == 0: return [] sort_keys, sort_dirs = _process_sort_params(sort_keys, sort_dirs) filters = filters or {} query = model_query(context, models.FailoverSegment) if 'recovery_method' in filters: query = query.filter(models.FailoverSegment.recovery_method == filters[ 'recovery_method']) if 'service_type' in filters: query = query.filter(models.FailoverSegment.service_type == filters[ 'service_type']) marker_row = None if marker is not None: marker_row = model_query(context, models.FailoverSegment ).filter_by(id=marker).first() if not marker_row: raise exception.MarkerNotFound(marker=marker) try: query = sqlalchemyutils.paginate_query(query, models.FailoverSegment, limit, sort_keys, marker=marker_row, sort_dirs=sort_dirs) except db_exc.InvalidSortKey as e: raise exception.InvalidSortKey(e) return query.all()
Example #4
Source File: test_utils.py From oslo.db with Apache License 2.0 | 5 votes |
def test_invalid_sort_key_str(self): self.assertEqual("Sort key supplied is invalid: None", str(exception.InvalidSortKey())) self.assertEqual("Sort key supplied is invalid: lol", str(exception.InvalidSortKey("lol")))
Example #5
Source File: test_utils.py From oslo.db with Apache License 2.0 | 5 votes |
def test_paginate_query_attribute_error(self): self.mock_asc.return_value = 'asc' self.assertRaises(exception.InvalidSortKey, utils.paginate_query, self.query, self.model, 5, ['user_id', 'non-existent key']) self.mock_asc.assert_called_once_with(self.model.user_id) self.query.order_by.assert_called_once_with('asc')
Example #6
Source File: test_utils.py From oslo.db with Apache License 2.0 | 5 votes |
def test_paginate_query_attribute_error_invalid_sortkey(self): self.assertRaises(exception.InvalidSortKey, utils.paginate_query, self.query, self.model, 5, ['bad_user_id'])
Example #7
Source File: test_utils.py From oslo.db with Apache License 2.0 | 5 votes |
def test_paginate_query_attribute_error_invalid_sortkey_2(self): self.assertRaises(exception.InvalidSortKey, utils.paginate_query, self.query, self.model, 5, ['foo'])
Example #8
Source File: test_utils.py From oslo.db with Apache License 2.0 | 5 votes |
def test_paginate_query_attribute_error_invalid_sortkey_3(self): self.assertRaises(exception.InvalidSortKey, utils.paginate_query, self.query, self.model, 5, ['asc-nullinvalid'])
Example #9
Source File: api.py From cyborg with Apache License 2.0 | 5 votes |
def _paginate_query(context, model, query, limit=None, marker=None, sort_key=None, sort_dir=None): sort_keys = ['id'] if sort_key and sort_key not in sort_keys: sort_keys.insert(0, sort_key) try: query = sqlalchemyutils.paginate_query(query, model, limit, sort_keys, marker=marker, sort_dir=sort_dir) except db_exc.InvalidSortKey: raise exception.InvalidParameterValue( _('The sort_key value "%(key)s" is an invalid field for sorting') % {'key': sort_key}) return query.all()
Example #10
Source File: api.py From masakari with Apache License 2.0 | 4 votes |
def host_get_all_by_filters( context, filters=None, sort_keys=None, sort_dirs=None, limit=None, marker=None): # NOTE(Dinesh_Bhor): If the limit is 0 there is no point in even going # to the database since nothing is going to be returned anyway. if limit == 0: return [] sort_keys, sort_dirs = _process_sort_params(sort_keys, sort_dirs) filters = filters or {} query = model_query(context, models.Host).options(joinedload('failover_segment')) if 'failover_segment_id' in filters: query = query.filter(models.Host.failover_segment_id == filters[ 'failover_segment_id']) if 'type' in filters: query = query.filter(models.Host.type == filters['type']) if 'on_maintenance' in filters: query = query.filter(models.Host.on_maintenance == filters[ 'on_maintenance']) if 'reserved' in filters: query = query.filter(models.Host.reserved == filters['reserved']) marker_row = None if marker is not None: marker_row = model_query(context, models.Host ).filter_by(id=marker).first() if not marker_row: raise exception.MarkerNotFound(marker=marker) try: query = sqlalchemyutils.paginate_query(query, models.Host, limit, sort_keys, marker=marker_row, sort_dirs=sort_dirs) except db_exc.InvalidSortKey as e: raise exception.InvalidSortKey(e) return query.all()
Example #11
Source File: api.py From masakari with Apache License 2.0 | 4 votes |
def notifications_get_all_by_filters( context, filters=None, sort_keys=None, sort_dirs=None, limit=None, marker=None): # NOTE(Dinesh_Bhor): If the limit is 0 there is no point in even going # to the database since nothing is going to be returned anyway. if limit == 0: return [] sort_keys, sort_dirs = _process_sort_params(sort_keys, sort_dirs) filters = filters or {} query = model_query(context, models.Notification) if 'source_host_uuid' in filters: query = query.filter(models.Notification.source_host_uuid == filters[ 'source_host_uuid']) if 'type' in filters: query = query.filter(models.Notification.type == filters['type']) if 'status' in filters: status = filters['status'] if isinstance(status, (list, tuple, set, frozenset)): column_attr = getattr(models.Notification, 'status') query = query.filter(column_attr.in_(status)) else: query = query.filter(models.Notification.status == status) if 'generated-since' in filters: generated_since = timeutils.normalize_time(filters['generated-since']) query = query.filter( models.Notification.generated_time >= generated_since) marker_row = None if marker is not None: marker_row = model_query(context, models.Notification ).filter_by(id=marker).first() if not marker_row: raise exception.MarkerNotFound(marker=marker) try: query = sqlalchemyutils.paginate_query(query, models.Notification, limit, sort_keys, marker=marker_row, sort_dirs=sort_dirs) except db_exc.InvalidSortKey as err: raise exception.InvalidSortKey(err) return query.all()