From 58444d9afcba4d23af461d5d4f104050f1b97733 Mon Sep 17 00:00:00 2001 From: Elias Gabriel Date: Tue, 3 Aug 2021 17:55:02 -0700 Subject: [PATCH] FIX: policy removal for non-filled models --- casbin_tortoise_adapter/adapter.py | 4 ++-- pyproject.toml | 2 +- tests/conftest.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/casbin_tortoise_adapter/adapter.py b/casbin_tortoise_adapter/adapter.py index ddd116d..7315673 100644 --- a/casbin_tortoise_adapter/adapter.py +++ b/casbin_tortoise_adapter/adapter.py @@ -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 @@ -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() diff --git a/pyproject.toml b/pyproject.toml index 5a136eb..1b97f5e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "Apache-2.0" diff --git a/tests/conftest.py b/tests/conftest.py index 52e36f5..609bc99 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -24,7 +24,7 @@ async def adapter(): }, "apps": {"my_app": {"models": ["casbin_tortoise_adapter"]}}, }, - _create_db=True, + # _create_db=True, ) await Tortoise.generate_schemas()