Browse Source

Merge "Fix with_entities usage in db queries" into stable/wallaby

stable/wallaby
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
6d7c220b46
1 changed files with 6 additions and 9 deletions
  1. +6
    -9
      manila/db/sqlalchemy/api.py

+ 6
- 9
manila/db/sqlalchemy/api.py View File

@ -46,7 +46,6 @@ from sqlalchemy import MetaData
from sqlalchemy import or_
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import subqueryload
from sqlalchemy.sql import distinct
from sqlalchemy.sql.expression import literal
from sqlalchemy.sql.expression import true
from sqlalchemy.sql import func
@ -2163,8 +2162,7 @@ def _share_get_all_with_filters(context, project_id=None, share_server_id=None,
# NOTE(carloss): Count must be calculated before limit and offset are
# applied into the query.
if show_count:
count = query.with_entities(
func.count(distinct(models.Share.id))).scalar()
count = query.count()
if 'limit' in filters:
offset = filters.get('offset', 0)
@ -5266,11 +5264,7 @@ def _share_group_snapshot_get_all(
sort_dir = 'desc'
query = model_query(
context, models.ShareGroupSnapshot, session=session, read_deleted='no',
).options(
joinedload('share_group'),
joinedload('share_group_snapshot_members'),
)
context, models.ShareGroupSnapshot, session=session, read_deleted='no')
# Apply filters
if not filters:
@ -5295,7 +5289,10 @@ def _share_group_snapshot_get_all(
raise exception.InvalidInput(reason=msg)
if detailed:
return query.all()
return query.options(
joinedload('share_group'),
joinedload('share_group_snapshot_members')
).all()
else:
query = query.with_entities(models.ShareGroupSnapshot.id,
models.ShareGroupSnapshot.name)


Loading…
Cancel
Save