diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-10-08 17:40:49 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-10-08 17:40:49 +0000 |
commit | 34c4b679fdc3e039d7f5d528ce360272af201164 (patch) | |
tree | f88d6d25af9b183ba778752bd7e7c0d6be891c00 /oslo_db/sqlalchemy/utils.py | |
parent | 8c41987f25202fc071fce34905729528068af58b (diff) | |
parent | 3a40168056b85de0e53b69dc6ff52bddb4cdd7a7 (diff) | |
download | oslo-db-34c4b679fdc3e039d7f5d528ce360272af201164.tar.gz |
Merge "Fix pagination when marker value is None"
Diffstat (limited to 'oslo_db/sqlalchemy/utils.py')
-rw-r--r-- | oslo_db/sqlalchemy/utils.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/oslo_db/sqlalchemy/utils.py b/oslo_db/sqlalchemy/utils.py index f0a3440..72aa364 100644 --- a/oslo_db/sqlalchemy/utils.py +++ b/oslo_db/sqlalchemy/utils.py @@ -241,7 +241,8 @@ def paginate_query(query, model, limit, sort_keys, marker=None, if marker_values[i] is not None: for j in range(i): model_attr = getattr(model, sort_keys[j]) - crit_attrs.append((model_attr == marker_values[j])) + if marker_values[j] is not None: + crit_attrs.append((model_attr == marker_values[j])) model_attr = getattr(model, sort_keys[i]) val = marker_values[i] @@ -250,9 +251,16 @@ def paginate_query(query, model, limit, sort_keys, marker=None, val = int(val) model_attr = cast(model_attr, Integer) if sort_dirs[i].startswith('desc'): - crit_attrs.append((model_attr < val)) + crit_attr = (model_attr < val) + if sort_dirs[i].endswith('nullsfirst'): + crit_attr = sqlalchemy.sql.or_(crit_attr, + model_attr.is_(None)) else: - crit_attrs.append((model_attr > val)) + crit_attr = (model_attr > val) + if sort_dirs[i].endswith('nullslast'): + crit_attr = sqlalchemy.sql.or_(crit_attr, + model_attr.is_(None)) + crit_attrs.append(crit_attr) criteria = sqlalchemy.sql.and_(*crit_attrs) criteria_list.append(criteria) |