fix(celery): store display_power in redis as a string, not a bool - #3032
Merged
Conversation
- diagnostics.get_display_power() returns str | bool; redis-py rejects a bool with DataError: Invalid input of type: 'bool', so every clean CEC True/False crashed the get_display_power task and left the key unset (Sentry ANTHIAS-2C, 32 events) - Coerce to str before r.set: the v2 System Info API exposes display_power as string | null and passes it through, so 'True'/'False'/'CEC error' all fit — and the on/off state now actually populates instead of only the error fallbacks landing - The existing test asserted the buggy bool write (a Mock redis accepted it); rewrite it to assert str coercion across True/False/ error, with an isinstance guard against the DataError Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a Celery task crash caused by attempting to write a Python bool to Redis via redis-py (which raises DataError for bool inputs). It ensures the display_power value is always stored as a string so the periodic task can successfully persist CEC power state.
Changes:
- Coerce
diagnostics.get_display_power()tostrbefore writing to Redis inget_display_power. - Update the Celery task unit test to assert string coercion for
True,False, and error-string cases via parametrization.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/anthias_server/celery_tasks.py |
Coerces CEC power query result to str before r.set(...) to prevent redis-py bool DataError. |
tests/test_celery_tasks.py |
Rewrites the test to validate Redis writes are strings across bool and error-string return values. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5 tasks
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.



Issues Fixed
Sentry ANTHIAS-2C —
DataError: Invalid input of type: 'bool'inget_display_power(32 events on the current2026.6.2+fe942a5build).Description
diagnostics.get_display_power()returnsstr | bool— a real bool for a clean CECTrue/False, a string for the error fallbacks.redis-pyrefuses a bool (DataError: Invalid input of type: 'bool'. Convert to a bytes, str, int or float first.), so every successful CEC power query crashed the task and left thedisplay_powerkey unset; only the error-string cases ever stored. The v2 System Info API exposesdisplay_powerasstring | nulland just passes the value through.r.set('display_power', str(diagnostics.get_display_power()))—'True'/'False'/'CEC error'all satisfy the API schema, and the on/off state now actually populatesMagicMockredis accepted what real redis rejects); rewritten to assert str coercion acrossTrue/False/error with anisinstance(str)guardChecklist
🤖 Generated with Claude Code