refactor: make the pending-subscription sentinel explicit - #56
Merged
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
`WSClient._should_subscribe_to_pending_job` holds `False` until a pending subscription is queued and a dict afterwards, and three places subscript it. The subscripts are safe, because the only path that reaches them tests the flag first, but the test was buried:
```python
if all([message.get('group_name') == 'jobs', message.get('status') == 'pending', message.get('unified_job_id'), self._should_subscribe_to_pending_job]):
if bool(message.get('project_id')) == (self._should_subscribe_to_pending_job['events'] == 'project_update_events'):
self._update_subscription(message['unified_job_id'])
```
Four unrelated conditions in an `all([...])`, one of them the guard for the line below it, and `_update_subscription` then reaching back for the attribute a second time rather than being handed it.
Three changes, none of which alters behaviour:
- The sentinel is `None` rather than `False`, annotated `dict | None`. Both are falsy and nothing compares it by identity or to `False`, so every existing check behaves the same. `None` is what "not set yet" means.
- The flag is bound to a local and tested first, with `and` instead of `all([...])`. Short-circuiting rather than eager evaluation, which is fine here since every element is a pure `.get()`.
- `_update_subscription` takes the dict as an argument instead of re-reading the attribute, so it cannot be called in a state where that attribute is unset.
Exercised the whole path directly, since the unit suite covers the callbacks but not this branch: queueing with `subscribe_to_pending_events('job_events')`, then feeding a pending-job message through `_on_message`, resubscribes with `{'jobs': ['status_changed'], 'job_events': [7]}` and clears the sentinel back to `None`.
Four diagnostics retired. Diffed the full list before and after: strict subset, nothing introduced.
Note for whoever merges: ctrliq#27 also edits this file, so whichever lands second needs a rebase.
Verified with `black --check`, `flake8` and the unit suite, 355 passing.
blaipr
force-pushed
the
refactor/pending-job-sentinel
branch
from
September 13, 2026 09:03
f73a33e to
a4edd0f
Compare
cigamit
approved these changes
Sep 13, 2026
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.
WSClient._should_subscribe_to_pending_jobholdsFalseuntil a pending subscription is queued and a dict afterwards, and three places subscript it. The subscripts are safe, because the only path that reaches them tests the flag first, but the test was buried:Four unrelated conditions in an
all([...]), one of them the guard for the line below it, and_update_subscriptionthen reaching back for the attribute a second time rather than being handed it.Three changes, none of which alters behaviour:
Nonerather thanFalse, annotateddict | None. Both are falsy and nothing compares it by identity or toFalse, so every existing check behaves the same.Noneis what "not set yet" means.andinstead ofall([...]). Short-circuiting rather than eager evaluation, which is fine here since every element is a pure.get()._update_subscriptiontakes the dict as an argument instead of re-reading the attribute, so it cannot be called in a state where that attribute is unset.Exercised the whole path directly, since the unit suite covers the callbacks but not this branch: queueing with
subscribe_to_pending_events('job_events'), then feeding a pending-job message through_on_message, resubscribes with{'jobs': ['status_changed'], 'job_events': [7]}and clears the sentinel back toNone.Four diagnostics retired. Diffed the full list before and after: strict subset, nothing introduced.
Note for whoever merges: #27 also edits this file, so whichever lands second needs a rebase.
Verified with
black --check,flake8and the unit suite, 355 passing.