Skip to content

fix(celery): store display_power in redis as a string, not a bool - #3032

Merged
vpetersson merged 1 commit into
masterfrom
fix/display-power-redis-str
Jun 9, 2026
Merged

fix(celery): store display_power in redis as a string, not a bool#3032
vpetersson merged 1 commit into
masterfrom
fix/display-power-redis-str

Conversation

@vpetersson

Copy link
Copy Markdown
Contributor

Issues Fixed

Sentry ANTHIAS-2CDataError: Invalid input of type: 'bool' in get_display_power (32 events on the current 2026.6.2+fe942a5 build).

Description

diagnostics.get_display_power() returns str | bool — a real bool for a clean CEC True/False, a string for the error fallbacks. redis-py refuses 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 the display_power key unset; only the error-string cases ever stored. The v2 System Info API exposes display_power as string | null and 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 populates
  • The existing test asserted the buggy bool write (the MagicMock redis accepted what real redis rejects); rewritten to assert str coercion across True/False/error with an isinstance(str) guard

Checklist

  • I have performed a self-review of my own code.
  • New and existing unit tests pass locally and on CI with my changes.
  • I have done an end-to-end test for Raspberry Pi devices.
  • I have tested my changes for x86 devices.
  • I added a documentation for the changes I have made (when necessary).

🤖 Generated with Claude Code

- 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]>
@vpetersson
vpetersson requested a review from a team as a code owner June 8, 2026 19:38
@vpetersson vpetersson self-assigned this Jun 8, 2026
@vpetersson
vpetersson requested a review from Copilot June 8, 2026 19:38
@sonarqubecloud

sonarqubecloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() to str before writing to Redis in get_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.

@vpetersson vpetersson mentioned this pull request Jun 9, 2026
5 tasks
@vpetersson
vpetersson merged commit 3b5ad78 into master Jun 9, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants