|
12 | 12 | from uuid import UUID as StdUUID # noqa: N811 |
13 | 13 |
|
14 | 14 | from pydantic import TypeAdapter |
15 | | -from sqlalchemy import DateTime, MetaData, func, select |
| 15 | +from sqlalchemy import DateTime, MetaData, func, inspect, select |
16 | 16 | from sqlalchemy.exc import OperationalError |
17 | 17 | from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine, create_async_engine |
| 18 | +from sqlalchemy.orm import DeclarativeBase |
18 | 19 | from uuid_utils import UUID, uuid7 |
19 | 20 |
|
20 | 21 | from diracx.core.exceptions import InvalidQueryError |
@@ -250,7 +251,7 @@ async def ping(self): |
250 | 251 |
|
251 | 252 | async def _search( |
252 | 253 | self, |
253 | | - table: Any, |
| 254 | + table: type[DeclarativeBase], |
254 | 255 | parameters: list[str] | None, |
255 | 256 | search: list[SearchSpec], |
256 | 257 | sorts: list[SortSpec], |
@@ -290,12 +291,15 @@ async def _search( |
290 | 291 | ] |
291 | 292 |
|
292 | 293 | async def _summary( |
293 | | - self, table: Any, group_by: list[str], search: list[SearchSpec] |
| 294 | + self, |
| 295 | + table: type[DeclarativeBase], |
| 296 | + group_by: list[str], |
| 297 | + search: list[SearchSpec], |
294 | 298 | ) -> list[dict[str, str | int]]: |
295 | 299 | """Get a summary of the elements of a table.""" |
296 | 300 | columns = _get_columns(table.__table__, group_by) |
297 | 301 |
|
298 | | - pk_columns = list(table.__table__.primary_key.columns) |
| 302 | + pk_columns = list(inspect(table).primary_key) |
299 | 303 | if not pk_columns: |
300 | 304 | raise ValueError( |
301 | 305 | "Model has no primary key and no count_column was provided." |
|
0 commit comments