Skip to content

Commit eb68f28

Browse files
authored
Merge pull request #13 from Muster-Suchen-und-Erkennen/update-dependencies
2 parents 34f98f6 + c7edfec commit eb68f28

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

muse_for_anything/api/v1_api/ontology_objects.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ def post(self, data, namespace: str, **kwargs):
355355
"Object type is marked as deleted. No new Objects of this type can be created!"
356356
),
357357
)
358+
if found_object_type.current_version is None:
359+
# can only create objects of a type which has a current version
360+
abort(
361+
HTTPStatus.BAD_REQUEST,
362+
message=gettext(
363+
"Object type has no current version. No Object can be created!"
364+
),
365+
)
358366
if not found_object_type.is_toplevel_type:
359367
# can only create objects for non abstract top level object type!
360368
abort(

muse_for_anything/db/models/ontology_objects.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ class OntologyObjectType(MODEL, IdMixin, NameDescriptionMixin, ChangesMixin):
3737
lazy="joined",
3838
primaryjoin="OntologyObjectType.current_version_id == OntologyObjectTypeVersion.id",
3939
)
40-
versions = relationship(
41-
"OntologyObjectTypeVersion",
40+
versions: Mapped[List["OntologyObjectTypeVersion"]] = relationship(
4241
lazy="select",
4342
order_by="OntologyObjectTypeVersion.version",
4443
back_populates="ontology_type",
4544
primaryjoin="OntologyObjectType.id == OntologyObjectTypeVersion.object_type_id",
4645
)
47-
ontology_objects: Mapped["OntologyObject"] = relationship(
46+
ontology_objects: Mapped[List["OntologyObject"]] = relationship(
4847
lazy="select",
4948
back_populates="ontology_type",
5049
)
@@ -137,7 +136,7 @@ def __table_args__(cls):
137136
back_populates="versions",
138137
primaryjoin=OntologyObjectType.id == object_type_id,
139138
)
140-
ontology_object_versions: Mapped["OntologyObjectVersion"] = relationship(
139+
ontology_object_versions: Mapped[List["OntologyObjectVersion"]] = relationship(
141140
lazy="select",
142141
back_populates="ontology_type_version",
143142
)
@@ -240,8 +239,7 @@ class OntologyObject(MODEL, IdMixin, NameDescriptionMixin, ChangesMixin):
240239
lazy="joined",
241240
primaryjoin="OntologyObject.current_version_id == OntologyObjectVersion.id",
242241
)
243-
versions = relationship(
244-
"OntologyObjectVersion",
242+
versions: Mapped[List["OntologyObjectVersion"]] = relationship(
245243
lazy="select",
246244
order_by="OntologyObjectVersion.version",
247245
back_populates="ontology_object",

muse_for_anything/db/pagination.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Dict, List, Optional, Sequence, Tuple, Type, TypeVar, Union
33

44
from sqlalchemy.orm.query import Query
5-
from sqlalchemy.sql import column, func
5+
from sqlalchemy.sql import column, func, select
66
from sqlalchemy.sql.expression import and_, asc, desc, or_
77
from sqlalchemy.sql.schema import Column
88
from sqlalchemy.sql.selectable import CTE
@@ -110,13 +110,17 @@ def get_page_info(
110110
# always include cursor row
111111
query_filter = or_(cursor_column == cursor, and_(*filter_criteria))
112112
item_query = model.query.filter(query_filter).order_by(order_by)
113-
cursor_row_cte: CTE = (
113+
cursor_row_subq = (
114114
DB.session.query(
115115
row_numbers.label("row"),
116116
cursor_column,
117117
)
118118
.filter(query_filter)
119-
.from_self(column("row"))
119+
.subquery()
120+
)
121+
122+
cursor_row_cte: CTE = (
123+
select(cursor_row_subq.c.row)
120124
.filter(cursor_column == cursor)
121125
.cte("cursor_row")
122126
)

0 commit comments

Comments
 (0)