Skip to content

Commit 739dd23

Browse files
committed
feat: fix SQLAlchemy 2.x compatibility in row iteration
1 parent a326c14 commit 739dd23

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ venv
44

55
__pycache__
66
outputs
7+
8+
# Python build artifacts
9+
*.egg-info/
10+
dist/
11+
build/
12+
*.pyc
13+
*.pyo

casbin_databases_adapter/adapter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ async def load_policy(self, model: Model):
2929
for row in rows:
3030
# convert row from tuple to csv format and removing the first column (id)
3131
line = [
32-
v for k, v in row._mapping.items() if k in self.cols and v is not None
32+
v
33+
for k, v in dict(row._mapping).items()
34+
if k in self.cols and v is not None
3335
]
3436
persist.load_policy_line(", ".join(line), model)
3537

@@ -84,7 +86,9 @@ async def load_filtered_policy(self, model: Model, filter_: Filter) -> None:
8486
for row in rows:
8587
# convert row from tuple to csv format and removing the first column (id)
8688
line = [
87-
v for k, v in row._mapping.items() if k in self.cols and v is not None
89+
v
90+
for k, v in dict(row._mapping).items()
91+
if k in self.cols and v is not None
8892
]
8993
persist.load_policy_line(", ".join(line), model)
9094

requirements-test.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
asynccasbin==1.1.7
2-
databases==0.7.0
3-
SQLAlchemy==1.4.42
2+
databases>=0.7.0
3+
SQLAlchemy>=1.4.42
44
pytest>=7.3.0
55
pytest-asyncio>=1.1.0
66
aiosqlite>=0.19.0

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
asynccasbin==1.1.7
2-
databases==0.7.0
3-
SQLAlchemy==1.4.42
2+
databases>=0.7.0
3+
SQLAlchemy>=1.4.42

0 commit comments

Comments
 (0)