adaptive-lighting: ULID must be 26 characters (HA 2023.4.)

Version information:

1.7.0 core-2023.4.0b2

Description:

Every change of the lights is followed by the following error of recorder:

2023-03-31 12:33:19.384 ERROR (Recorder) [homeassistant.components.recorder.core] Error while processing event EventTask(event=<Event call_service[L]: domain=light, service=turn_on, service_data=entity_id=light.lightstrip_regal_nanoleaf_light_strip, brightness=255, color_temp_kelvin=5460>): ULID must be 26 characters Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 825, in _guarded_process_one_task_or_recover self._process_one_task_or_recover(task) File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 836, in _process_one_task_or_recover return task.run(self) File "/usr/src/homeassistant/homeassistant/components/recorder/tasks.py", line 281, in run instance._process_one_event(self.event) File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 944, in _process_one_event self._process_non_state_changed_event_into_session(event) File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 953, in _process_non_state_changed_event_into_session dbevent = Events.from_event(event) File "/usr/src/homeassistant/homeassistant/components/recorder/db_schema.py", line 274, in from_event context_id_bin=ulid_to_bytes_or_none(event.context.id), File "/usr/src/homeassistant/homeassistant/components/recorder/models/context.py", line 15, in ulid_to_bytes_or_none return ulid_to_bytes(ulid) File "src/ulid_transform/_ulid_impl.pyx", line 22, in ulid_transform._ulid_impl._ulid_to_bytes ValueError: ULID must be 26 characters

Issue persists since 2023.4.0b0.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

It looks like home assistant lowered the max length of a context id from 36 to 26 for some reason in core-2023.4.0b0

That’s rather annoying.

If you go to line 200 or so in /config/custom_components/adaptive-lighting/switch.py you’ll see the line:

context_id = f"{_DOMAIN_SHORT}:{name_hash}:{which}:{index_packed}"[:36] just change the 36 to a 26 and restart home assistant core.

If you’re uncomfortable changing the code yourself, I could upload the hotfix here if you like.

Most likely nothing will be released into Adaptive Lighting until core-2023.4.0 is released and all the breaking changes are posted.

https://github.com/basnijholt/adaptive-lighting/pull/550 is probably fine.

We aren’t likely to change the context id format again anytime soon but there is always a chance.

As long as ulid_transform.ulid_to_bytes gives you back bytes everything should work

>>> ulid_transform.ulid_to_bytes('0001HZX0NW00GW0X476W5TVBFE')
b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee'

Closed as not planned, but in reality, this problem shouldn’t pop up anymore.

Our context ids are now 26 chars.

Update to 1.10.1 to get the fix 😃

The context id needs to be a ULID. This won’t be labeled as breaking change as HA isn’t designed to accept arbitrary data in the Context id field and it won’t be supported. The only thing that should be generating the id is the Context object or HA internals.

In practice you can base32 encode any string https://www.crockford.com/base32.html and pad it to get 26 characters but there are no promises it won’t break in the future.

You might be able to subclass Context and add a new field instead of abusing the id field. That wouldn’t be supported either but its probably less likely to break in the future if it works