From 0efbc57c1485422885dec8ffdfd266cf6c36de76 Mon Sep 17 00:00:00 2001 From: sunhs Date: Sat, 24 Apr 2021 00:56:34 +0800 Subject: [PATCH] fix `remove_policies` --- casbin_sqlalchemy_adapter/adapter.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/casbin_sqlalchemy_adapter/adapter.py b/casbin_sqlalchemy_adapter/adapter.py index e88225f..ab58a79 100644 --- a/casbin_sqlalchemy_adapter/adapter.py +++ b/casbin_sqlalchemy_adapter/adapter.py @@ -153,11 +153,14 @@ def remove_policy(self, sec, ptype, rule): def remove_policies(self, sec, ptype, rules): """removes a policy rules from the storage.""" + if not rules: + return with self._session_scope() as session: query = session.query(self._db_class) query = query.filter(self._db_class.ptype == ptype) - for rule in rules: - query = query.filter(or_(getattr(self._db_class, "v{}".format(i)) == v for i, v in enumerate(rule))) + rules = zip(*rules) + for i, rule in enumerate(rules): + query = query.filter(or_(getattr(self._db_class, "v{}".format(i)) == v for v in rule)) query.delete() def remove_filtered_policy(self, sec, ptype, field_index, *field_values):