Skip to content

Commit c956ee4

Browse files
Merge pull request #179 from jinyoungmoonDEV/master
add: select query에 sort가 있을시 default하게 id로 order_by 추가
2 parents ddc92cd + b480cc1 commit c956ee4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/spaceone/core/model/mongo_model/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,12 @@ def _stat_with_pipeline(
645645
)
646646

647647
if sort:
648-
aggregate.append({"sort": sort})
648+
# Add id as default sort if not already specified
649+
sort_with_id = sort.copy()
650+
has_id_sort = any(s.get("key") == "id" for s in sort_with_id)
651+
if not has_id_sort:
652+
sort_with_id.append({"key": "id", "desc": False})
653+
aggregate.append({"sort": sort_with_id})
649654

650655
response = cls.stat(
651656
aggregate=aggregate,
@@ -724,7 +729,7 @@ def query(
724729
_order_by.append(f'{sort_option["key"]}')
725730

726731
if sort:
727-
_order_by.append("_id")
732+
_order_by.append("id")
728733

729734
try:
730735
vos = cls._get_target_objects(target).filter(_filter)

0 commit comments

Comments
 (0)