Repository navigation
Regression on set_state api call #2531
Description
Activity
Edit: this analysis applies to the released 4.5.13 only — the bug is already fixed on
devby #2594, confirmed by an end-to-end test in my follow-up below. Reopen request withdrawn.
Just hit this independently on a fresh 4.5.13 install (Docker) and can confirm it's not fixed — reproduces exactly as described above, with a minimal repro that doesn't even need a running HA instance:
$ docker exec appdaemon python -c "import appdaemon.utils as u; print(u.clean_http_kwargs({'attributes':{'flag_false':False,'flag_true':True,'count':0}}))" {'attributes': {'flag_true': 'true'}}flag_falseandcount(0) are gone;flag_truesurvives but as the string"true", not a JSON bool.Current source is unchanged from what's already quoted in #2464:
# appdaemon/utils.py def clean_http_kwargs(val: Any) -> Any: """Recursively cleans the kwarg dict to prepare it for use in HTTP requests.""" cleaned = clean_kwargs(val, http=True) pruned = remove_literals(cleaned, (None, False)) return pruned
I think this is why #2475 (titled "only clean query parameters") didn't actually close this out:
HassPlugin.http_methodcallsclean_http_kwargsunconditionally, before branching on HTTP method:# appdaemon/plugins/hass/hassplugin.py, http_method() kwargs = utils.clean_http_kwargs(kwargs) ... match method.lower(): case "get": http_method = functools.partial(self.session.get, params=kwargs) case "post": http_method = functools.partial(self.session.post, json=kwargs) case "delete": http_method = functools.partial(self.session.delete, params=kwargs)
So the
False/0-dropping,True-stringifying cleanup (which makes sense for a GET query string) still runs on thekwargsthat become the POST JSON body viaset_state/call_service, contrary to the PR's own description ("There is no need to 'clean' the json body of a POST request... that wasn't done in 4.4.x"). Moving theclean_http_kwargscall inside the"get"/"delete"branches only, and leaving"post"'skwargsas real Python types (maybe just a datetime→isoformat pass for JSON-serializability), looks like it would fix this without touching GET/DELETE query-param handling.#2640 suggests this is still affecting people in the wild as recently as last month, also on 4.5.13. Could this be reopened, given it reproduces identically to the original report on the exact version it was closed against?
Root-cause tracing and this write-up were AI-assisted (Claude).
4.5.13 was released back in january. Patch for this issue was applied in May so 4.5.13 definitely has the bug. You might want to test on the github version (I confess I have not done so)
@jfparis Confirmed — I just tested the GitHub
devversion end-to-end (throwaway container,pip installof the dev tarball → 4.5.14-dev, pointed at a live HA instance), publishing viaset_state(..., replace=True):attributes={ "probe_false": False, "probe_true": True, "probe_zero": 0, "probe_zero_float": 0.0, "probe_none": None, "probe_str": "x", }
HA's
/api/statesafterwards:"attributes": { "probe_false": false, "probe_true": true, "probe_zero": 0, "probe_zero_float": 0.0, "probe_none": null, "probe_str": "x" }
Everything preserved, with real JSON types — note
trueis a proper boolean again, not the string"true"that 4.5.12/4.5.13 produce. The fix is #2594 ("Fix set_state dropping False, 0, and None values", merged to dev 2026-05-13 — the same day this issue was closed, so the closure was right and my reopen request above is withdrawn): on dev, POST bodies are no longer cleaned at all, query-param cleaning moved to a dedicatedclean_http_params_for_urlencode(), andremove_literals()now uses identity checks to dodge the0 == Falsepitfall.So the only remaining gap is a release — 4.5.13 (2026-01-19) predates the fix and is still the latest, which is presumably why this keeps getting re-reported from released installs (#2640). Maintainers: any chance of cutting a release that includes #2594?
Testing and write-up were AI-assisted.
We will have a release soon.
Reacted by Mikkel EskildsenReacted by Jean-François ParisStill blocked on 4.4 - a version from 2 years ago - due to this. Would it be possible to get a release?
What happened?
A little while back I posted about a regression with the set_state api call. (issue #2464 )
Whilst some changes were made the issue is still here for me. Every time I set a state, every attribute that is equal to False or 0 will be ignored
I created a small applet below
If you run that code with version 4.5.11, you get an entity with the following attributes
If you run it with 4.5.12 or 4.5.13 you get the following attributes
Version
4.5.13
Installation type
Python virtual environment
Relevant log output
Relevant code in the app or config file that caused the issue
Anything else?
No response