Skip to content

Commit

Permalink
FIX: policy removal for non-filled models
Browse files Browse the repository at this point in the history
  • Loading branch information
thearchitector committed Aug 4, 2021
1 parent b7a649e commit 58444d9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions casbin_tortoise_adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def add_policies(self, sec: str, ptype: str, rules: List[RuleType]):

async def remove_policy(self, sec: str, ptype: str, rule: RuleType):
"""Removes a policy rule from storage."""
vs = {f"v{i}": rule[i] if len(rule) > i else "" for i in range(6)}
vs = {f"v{i}": rule[i] for i in range(6) if len(rule) > i}
r = await self.modelclass.filter(ptype=ptype, **vs).delete()
return r > 0

Expand All @@ -70,7 +70,7 @@ async def remove_policies(self, sec, ptype, rules: List[RuleType]):
return

qs = [
Q(**{f"v{i}": rule[i] if len(rule) > i else "" for i in range(6)})
Q(**{f"v{i}": rule[i] for i in range(6) if len(rule) > i})
for i, rule in enumerate(rules)
]
await self.modelclass.filter(Q(*qs, join_type=Q.OR), ptype=ptype).delete()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "casbin-tortoise-adapter"
version = "1.0.0.post1"
version = "1.0.1"
description = "Tortoise ORM adapter for AsyncCasbin"
authors = ["Elias Gabriel <me@eliasfgabriel.com>"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def adapter():
},
"apps": {"my_app": {"models": ["casbin_tortoise_adapter"]}},
},
_create_db=True,
# _create_db=True,
)
await Tortoise.generate_schemas()

Expand Down

0 comments on commit 58444d9

Please sign in to comment.