Skip to content

Commit

Permalink
feat: sqlalchemy v2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Sep 7, 2024
1 parent cdfe76c commit 0275236
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ckanext/collection/utils/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 7 additions & 5 deletions ckanext/collection/utils/serialize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 0275236

Please sign in to comment.