@@ -113,7 +113,10 @@ async def save_policy(self):
113113 else :
114114 update_for_save_policy (self .model )
115115 else :
116- self .watcher .update ()
116+ if inspect .iscoroutinefunction (self .watcher .update ):
117+ await self .watcher .update ()
118+ else :
119+ self .watcher .update ()
117120
118121 async def _add_policy (self , sec , ptype , rule ):
119122 """async adds a rule to the current policy."""
@@ -133,7 +136,10 @@ async def _add_policy(self, sec, ptype, rule):
133136 else :
134137 update_for_add_policy (sec , ptype , rule )
135138 else :
136- self .watcher .update ()
139+ if inspect .iscoroutinefunction (self .watcher .update ):
140+ await self .watcher .update ()
141+ else :
142+ self .watcher .update ()
137143
138144 rule_added = self .model .add_policy (sec , ptype , rule )
139145
@@ -161,7 +167,10 @@ async def _add_policies(self, sec, ptype, rules):
161167 else :
162168 update_for_add_policies (sec , ptype , rules )
163169 else :
164- self .watcher .update ()
170+ if inspect .iscoroutinefunction (self .watcher .update ):
171+ await self .watcher .update ()
172+ else :
173+ self .watcher .update ()
165174
166175 rules_added = self .model .add_policies (sec , ptype , rules )
167176
@@ -180,7 +189,10 @@ async def _update_policy(self, sec, ptype, old_rule, new_rule):
180189 return False
181190
182191 if self .watcher and self .auto_notify_watcher :
183- self .watcher .update ()
192+ if inspect .iscoroutinefunction (self .watcher .update ):
193+ await self .watcher .update ()
194+ else :
195+ self .watcher .update ()
184196
185197 return rule_updated
186198
@@ -197,7 +209,10 @@ async def _update_policies(self, sec, ptype, old_rules, new_rules):
197209 return False
198210
199211 if self .watcher and self .auto_notify_watcher :
200- self .watcher .update ()
212+ if inspect .iscoroutinefunction (self .watcher .update ):
213+ await self .watcher .update ()
214+ else :
215+ self .watcher .update ()
201216
202217 return rules_updated
203218
@@ -225,7 +240,10 @@ async def _update_filtered_policies(self, sec, ptype, new_rules, field_index, *f
225240 if sec == "g" :
226241 self .build_role_links ()
227242 if self .watcher and self .auto_notify_watcher :
228- self .watcher .update ()
243+ if inspect .iscoroutinefunction (self .watcher .update ):
244+ await self .watcher .update ()
245+ else :
246+ self .watcher .update ()
229247 return is_rule_changed
230248
231249 async def _remove_policy (self , sec , ptype , rule ):
@@ -247,7 +265,10 @@ async def _remove_policy(self, sec, ptype, rule):
247265 else :
248266 update_for_remove_policy (sec , ptype , rule )
249267 else :
250- self .watcher .update ()
268+ if inspect .iscoroutinefunction (self .watcher .update ):
269+ await self .watcher .update ()
270+ else :
271+ self .watcher .update ()
251272
252273 return rule_removed
253274
@@ -273,7 +294,10 @@ async def _remove_policies(self, sec, ptype, rules):
273294 else :
274295 update_for_remove_policies (sec , ptype , rules )
275296 else :
276- self .watcher .update ()
297+ if inspect .iscoroutinefunction (self .watcher .update ):
298+ await self .watcher .update ()
299+ else :
300+ self .watcher .update ()
277301
278302 return rules_removed
279303
@@ -296,7 +320,10 @@ async def _remove_filtered_policy(self, sec, ptype, field_index, *field_values):
296320 else :
297321 update_for_remove_filtered_policy (sec , ptype , field_index , * field_values )
298322 else :
299- self .watcher .update ()
323+ if inspect .iscoroutinefunction (self .watcher .update ):
324+ await self .watcher .update ()
325+ else :
326+ self .watcher .update ()
300327
301328 return rule_removed
302329
@@ -312,7 +339,10 @@ async def _remove_filtered_policy_returns_effects(self, sec, ptype, field_index,
312339 return False
313340
314341 if self .watcher and self .auto_notify_watcher :
315- self .watcher .update ()
342+ if inspect .iscoroutinefunction (self .watcher .update ):
343+ await self .watcher .update ()
344+ else :
345+ self .watcher .update ()
316346
317347 return rule_removed
318348
0 commit comments