Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filtering skip_patterns #868

Merged
merged 2 commits into from Aug 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion aiogram/dispatcher/middlewares.py
Expand Up @@ -110,6 +110,19 @@ class LifetimeControllerMiddleware(BaseMiddleware):
# TODO: Rename class

skip_patterns = None
_skip_actions = None

@property
def skip_actions(self):
if self._skip_actions is None:
self._skip_actions = []
if self.skip_patterns:
self._skip_actions.extend([
f"pre_process_{item}",
f"process_{item}",
f"post_process_{item}",
])
return self._skip_actions

async def pre_process(self, obj, data, *args):
pass
Expand All @@ -118,7 +131,7 @@ async def post_process(self, obj, data, *args):
pass

async def trigger(self, action, args):
if self.skip_patterns is not None and any(item in action for item in self.skip_patterns):
if action in self.skip_actions:
return False

obj, *args, data = args
Expand Down