bug: notify.py crashes on non-string targets due to unguarded json.loads() (TypeError)
bugpr submittedalexa_media
## Summary
In `custom_components/alexa_media/notify.py` (lines 219–229), `json.loads(target)` is called without a type guard. Non-string target entries (e.g., dict, list, int) raise `TypeError`, which is **not** caught by the `except json.JSONDecodeError` clause. This aborts the entire notification send path for any non-string target.
The existing tests explicitly document that "non-string targets are passed through unchanged", but this contract is broken at runtime.
## Severity
**Blocker** — any non-string target in `ATTR_TARGET` will raise an unhandled `TypeError` and abort `async_send_message`.
## Proposed Fix
Add an `isinstance(target, str)` guard before calling `json.loads()` and append non-string targets directly to `processed_targets`:
```python
for target in targets:
_LOGGER.debug("Processing: %s", target)
if not isinstance(target, str):
processed_targets.append(target)
_LOGGER.debug("Processed non-string target: %s", processed_targets)
continue
try:
parsed = json.loads(target)
if isinstance(parsed, list):
processed_targets.extend(parsed)
else:
processed_targets.append(parsed)
_LOGGER.debug("Processed Target by json: %s", processed_targets)
except json.JSONDecodeError:
if "," in target:
processed_targets += [item.strip() for item in target.split(",") if item.strip()]
else:
processed_targets.append(target.strip())
_LOGGER.debug("Processed Target by string: %s", processed_targets)
```
Also add a regression test for non-string target pass-through in `tests/test_notify.py`.
## References
- Introduced in: #3446 (by @danielbrunt57)
- Identified in: #3450
- Requested by: @alandtse
关闭于 2026-05-16 3 条评论