Skip to content

Commit 3d3b7df

Browse files
committed
self
1 parent 064a277 commit 3d3b7df

File tree

1 file changed

+13
-11
lines changed
  • services/web/server/src/simcore_service_webserver/projects

1 file changed

+13
-11
lines changed

services/web/server/src/simcore_service_webserver/projects/db.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import logging
99
from contextlib import AsyncExitStack
10-
from typing import Any, cast
10+
from typing import Any, Self, cast
1111
from uuid import uuid1
1212

1313
import sqlalchemy as sa
@@ -43,6 +43,7 @@
4343
from simcore_postgres_database.models.projects_tags import projects_tags
4444
from simcore_postgres_database.models.projects_to_folders import projects_to_folders
4545
from simcore_postgres_database.models.projects_to_products import projects_to_products
46+
from simcore_postgres_database.models.projects_to_wallet import projects_to_wallet
4647
from simcore_postgres_database.models.wallets import wallets
4748
from simcore_postgres_database.models.workspaces_access_rights import (
4849
workspaces_access_rights,
@@ -64,7 +65,6 @@
6465
from tenacity.asyncio import AsyncRetrying
6566
from tenacity.retry import retry_if_exception_type
6667

67-
from ..db.models import projects_tags, projects_to_wallet
6868
from ..utils import now_str
6969
from ._comments_db import (
7070
create_project_comment,
@@ -104,6 +104,10 @@
104104
APP_PROJECT_DBAPI = __name__ + ".ProjectDBAPI"
105105
ANY_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

Comments
 (0)