From 02752363b6b75623d0c713025409660706bd733b Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Sat, 7 Sep 2024 23:40:53 +0300 Subject: [PATCH] feat: sqlalchemy v2 compatibility --- .github/workflows/test.yml | 2 +- ckanext/collection/utils/data/model.py | 2 +- ckanext/collection/utils/serialize/__init__.py | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c3b7f93..475859d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - ckan-version: ["2.11", "2.10"] + ckan-version: ["2.11", "2.10", "2.11"] fail-fast: false runs-on: ubuntu-latest diff --git a/ckanext/collection/utils/data/model.py b/ckanext/collection/utils/data/model.py index 7e806de..9db9c53 100644 --- a/ckanext/collection/utils/data/model.py +++ b/ckanext/collection/utils/data/model.py @@ -512,7 +512,7 @@ def apply_joins(self, stmt: Select) -> Select: sources = self.extra_sources for name, condition, isouter in self.get_joins(): - stmt = stmt.join(sources[name], condition, isouter) + stmt = stmt.join(sources[name], condition, isouter=isouter) return stmt diff --git a/ckanext/collection/utils/serialize/__init__.py b/ckanext/collection/utils/serialize/__init__.py index 53c2499..601e33c 100644 --- a/ckanext/collection/utils/serialize/__init__.py +++ b/ckanext/collection/utils/serialize/__init__.py @@ -38,17 +38,19 @@ def basic_row_dictizer(row: Any) -> dict[str, Any]: return cast("dict[str, Any]", row) if isinstance(row, Row): - return dict(zip(row.keys(), row)) + if hasattr(row, "_asdict"): + return row._asdict() # # type: ignore + + if hasattr(row, "keys"): + return dict(zip(row.keys(), row)) try: - reflection = sa.inspect( # pyright: ignore[reportUnknownVariableType] - row, - ) + reflection = sa.inspect(row) except NoInspectionAvailable: raise TypeError(type(row)) from None if isinstance(reflection, InstanceState): - return {attr.key: attr.value for attr in reflection.attrs} # pyright: ignore + return {attr.key: attr.value for attr in reflection.attrs} raise TypeError(type(row))