fix: handle no gateway priority configured case#18
Open
Mrsandeep27 wants to merge 1 commit into
Open
Conversation
Previously, when a channel had no default_priority and no dynamic
priority (either unconfigured or an eval that returned []), the call
to select_gateway would:
- silently swallow the eval error (just `pass`),
- compute total_gateways = 0 and crash with ZeroDivisionError on
`current_priority[n_attempts % 0]`.
Changes:
- Raise a dedicated NoGatewayPriorityConfigured when both the
evaluated and default priorities are empty, so callers can log
and skip cleanly instead of hitting a ZeroDivisionError.
- Log the eval failure (previously intentionally silenced) so
misconfigured priority expressions surface in logs.
- In AbstractHandler.notify, short-circuit when ENABLED_GATEWAYS_COUNT
is 0 and catch NoGatewayPriorityConfigured, logging the channel
and skipping the send instead of crashing.
Fixes tata1mg#13
|
DeputyDev will no longer review pull requests automatically.To request a review, simply comment #review on your pull request—this will trigger an on-demand review whenever you need it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #13 — when a channel has no gateway priority configured, the handler now logs and skips cleanly instead of raising ZeroDivisionError.
Problem
`PriorityGatewaySelection.select_gateway` computes:
```python
total_gateways = min(len(cls.get_default_priority()), len(current_priority))
return current_priority[n_attempts % total_gateways]
```
If both `default_priority` and `current_priority` are empty (channel configured with no priorities, or dynamic-priority expression evaluated to `[]`), `total_gateways` is `0` and the modulo raises `ZeroDivisionError`.
Additionally, the existing code silently swallows errors from `eval(priority_logic_expression)` — the comment says "Log the exception and fallback to default priority order" but the `except` block is just `pass`.
Fix
Test plan