Title: Safe Stop Propagation Propose · Issue #69 · hydrogram/hydrogram · GitHub
Open Graph Title: Safe Stop Propagation Propose · Issue #69 · hydrogram/hydrogram
X Title: Safe Stop Propagation Propose · Issue #69 · hydrogram/hydrogram
Description: Checklist I believe the idea is awesome and would benefit the framework I have searched in the issue tracker for similar requests, including closed ones Description When we want to ensure that a user marked as banned cannot interact, we ...
Open Graph Description: Checklist I believe the idea is awesome and would benefit the framework I have searched in the issue tracker for similar requests, including closed ones Description When we want to ensure that a us...
X Description: Checklist I believe the idea is awesome and would benefit the framework I have searched in the issue tracker for similar requests, including closed ones Description When we want to ensure that a us...
Opengraph URL: https://github.com/hydrogram/hydrogram/issues/69
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Safe Stop Propagation Propose","articleBody":"### Checklist\n\n- [x] I believe the idea is awesome and would benefit the framework\n- [x] I have searched in the issue tracker for similar requests, including closed ones\n\n### Description\n\nWhen we want to ensure that a user marked as banned cannot interact, we consider three things:\n\n1. Repeating code at the top of the handler function body to validate whether the user is banned. (It doesn't look nice, but you have control.)\n\n2. Using a decorator that performs the validations for you. (It's not much different from the first option; after all, you still repeat code above the functions, but you still have control.)\n\n3. Defining a handler with a higher group/priority and using `StopPropagation`. (It seems much more practical, BUT, if the handler unexpectedly breaks before you call `StopPropagation`, the banned user will bypass this validation layer; wrapping the entire function in a `try` will be necessary.)\n\n---\n\nI really like the third option, it would be interesting if we could define it as StopPropagation (to ensure that it does not propagate even if an error occurs) before validation, and after using CotinuePropagation, for example:\n\n```python\n\nasync def layer_check_user_banned(client: Client, message: Message):\n user = ......\n if user.banned:\n raise StopPropagation\n\n@Client.on_message(group=-1)\nasync def setup(client: Client, message: Message):\n await update.stop_propagation()\n\n layers = (layer_check_user_banned, layer_check_user_has_username, .....)\n for layer in layers:\n await layer(client, message)\n\n await update.continue_propagation()\n```\n----\nAlternatively I'm using decorators in these security layers to catch the error and rethrow it as `StopPropagation`:\n\n```python\ndef layer(function):\n async def _decorator(*args, **kwargs):\n try:\n return await function(*args, **kwargs)\n except StopPropagation:\n raise\n except Exception as e:\n logging.error(\n f'Layer {function.__name__!r} traceback:',\n exc_info=e\n )\n raise StopPropagation\n return _decorator\n```","author":{"url":"https://github.com/d3cryptofc","@type":"Person","name":"d3cryptofc"},"datePublished":"2025-07-13T22:50:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/69/hydrogram/issues/69"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:42d72036-a2ee-5e0b-8474-d611df0b68f2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8FFA:209E7C:5124196:6E0649C:6973220B |
| html-safe-nonce | 4fe8e829a64aa3b04270c4574fee8a05e230126ee9383827de76e5d065470dbd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkZBOjIwOUU3Qzo1MTI0MTk2OjZFMDY0OUM6Njk3MzIyMEIiLCJ2aXNpdG9yX2lkIjoiNDEzNzkxOTEwODQ2NjU0OTI2MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 66fd224554f5fc36392915daccd1a4cc65c67db9dd09f9146e1b03a7ec873d49 |
| hovercard-subject-tag | issue:3226898937 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/hydrogram/hydrogram/69/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4fcb73e029c10f715527079f69ebcf0e1ef9365f0d76aa62129cbeb506a046ef/hydrogram/hydrogram/issues/69 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4fcb73e029c10f715527079f69ebcf0e1ef9365f0d76aa62129cbeb506a046ef/hydrogram/hydrogram/issues/69 |
| og:image:alt | Checklist I believe the idea is awesome and would benefit the framework I have searched in the issue tracker for similar requests, including closed ones Description When we want to ensure that a us... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | d3cryptofc |
| hostname | github.com |
| expected-hostname | github.com |
| None | 44ab3188c1dcfe3be0f9c3feca2e04e14fb79f120939ce2395e4f15ab96ec1d4 |
| turbo-cache-control | no-preview |
| go-import | github.com/hydrogram/hydrogram git https://github.com/hydrogram/hydrogram.git |
| octolytics-dimension-user_id | 153278131 |
| octolytics-dimension-user_login | hydrogram |
| octolytics-dimension-repository_id | 711555265 |
| octolytics-dimension-repository_nwo | hydrogram/hydrogram |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 711555265 |
| octolytics-dimension-repository_network_root_nwo | hydrogram/hydrogram |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a5e2b48bd1260476599758f5d253b5d24092ab84 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width