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):