77
88import logging
99from contextlib import AsyncExitStack
10- from typing import Any , cast
10+ from typing import Any , Self , cast
1111from uuid import uuid1
1212
1313import sqlalchemy as sa
4343from simcore_postgres_database .models .projects_tags import projects_tags
4444from simcore_postgres_database .models .projects_to_folders import projects_to_folders
4545from simcore_postgres_database .models .projects_to_products import projects_to_products
46+ from simcore_postgres_database .models .projects_to_wallet import projects_to_wallet
4647from simcore_postgres_database .models .wallets import wallets
4748from simcore_postgres_database .models .workspaces_access_rights import (
4849 workspaces_access_rights ,
6465from tenacity .asyncio import AsyncRetrying
6566from tenacity .retry import retry_if_exception_type
6667
67- from ..db .models import projects_tags , projects_to_wallet
6868from ..utils import now_str
6969from ._comments_db import (
7070 create_project_comment ,
104104APP_PROJECT_DBAPI = __name__ + ".ProjectDBAPI"
105105ANY_USER = ANY_USER_ID_SENTINEL
106106
107+ DEFAULT_ORDER_BY = OrderBy (
108+ field = IDStr ("last_change_date" ), direction = OrderDirection .DESC
109+ )
110+
107111# pylint: disable=too-many-public-methods
108112# NOTE: https://github.com/ITISFoundation/osparc-simcore/issues/3516
109113
@@ -121,16 +125,16 @@ def _init_engine(self) -> None:
121125 raise ValueError (msg )
122126
123127 @classmethod
124- def get_from_app_context (cls , app : web .Application ) -> "ProjectDBAPI" :
125- db : "ProjectDBAPI" = app [APP_PROJECT_DBAPI ]
128+ def get_from_app_context (cls , app : web .Application ) -> Self :
129+ db = app [APP_PROJECT_DBAPI ]
130+ assert isinstance (db , cls ) # nosec
126131 return db
127132
128133 @classmethod
129- def set_once_in_app_context (cls , app : web .Application ) -> "ProjectDBAPI" :
134+ def set_once_in_app_context (cls , app : web .Application ) -> Self :
130135 if app .get (APP_PROJECT_DBAPI ) is None :
131- app [APP_PROJECT_DBAPI ] = ProjectDBAPI (app )
132- db : ProjectDBAPI = app [APP_PROJECT_DBAPI ]
133- return db
136+ app [APP_PROJECT_DBAPI ] = cls (app )
137+ return cls .get_from_app_context (app )
134138
135139 @property
136140 def engine (self ) -> Engine :
@@ -374,9 +378,7 @@ async def list_projects( # pylint: disable=too-many-arguments,too-many-statemen
374378 offset : int | None = 0 ,
375379 limit : int | None = None ,
376380 # order
377- order_by : OrderBy = OrderBy (
378- field = IDStr ("last_change_date" ), direction = OrderDirection .DESC
379- ),
381+ order_by : OrderBy = DEFAULT_ORDER_BY ,
380382 ) -> tuple [list [dict [str , Any ]], list [ProjectType ], int ]:
381383
382384 if filter_tag_ids_list is None :
0 commit comments