Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error migrating calendar if connection_timeout is not set #151

Closed
ccMatrix opened this issue Sep 11, 2024 · 11 comments · Fixed by #156
Closed

Error migrating calendar if connection_timeout is not set #151

ccMatrix opened this issue Sep 11, 2024 · 11 comments · Fixed by #156
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@ccMatrix
Copy link
Contributor

I've updated ics_calendar from latest 4 to 5 and had the following error in the log:

2024-09-11 07:33:12.463 ERROR (SyncWorker_3) [homeassistant.helpers.json] Failed to serialize to JSON: /config/.storage/core.config_entries. Bad data at $.data.entries[97].data.connection_timeout=<object object at 0xf6347e08>(<class 'object'>
2024-09-11 07:33:12.470 ERROR (MainThread) [homeassistant.helpers.storage] Error writing config for core.config_entries: Failed to serialize to JSON: /config/.storage/core.config_entries. Bad data at $.data.entries[97].data.connection_timeout=<object object at 0xf6347e08>(<class 'object'>

I did not have connection_timeout set in the yaml configuration. After I saw the error I added a line connection_timeout: 15 to the yaml and restarted home assistant which imported the yaml configuration into the core.config_entries file properly.

@Muenchen-Michi
Copy link

I had the same error, but did not recognize, that it's a problem with a missing settings in the old configuration, so I returned to version 4.2.0.

But this error is critical, because it stops HA from saving any new configuration. I added new integrations, that were all gone after a restart of HA. After going back to v4.2.0 and reinstalling my new integrations everything seems to work.
So I guess, v5.0.0 with the error writing the config is a severe problem, especially because you don't see in the log that this problem is caused by ics_calendar.

@wralb
Copy link

wralb commented Sep 11, 2024

Thanks @ccMatrix, I also had to include the reference to connection_timout to get the migration to proceed. I also found that new entities with _2 appended were created and I had to delete theold, and rename the new so they would work with all my templates and automations.

@franc6
Copy link
Owner

franc6 commented Sep 11, 2024

I've not been able to reproduce this one so far -- my own import data never included connection_timeout, since it's not something I've ever needed to adjust. It'll probably be a while before I can get to this. :(

@franc6 franc6 self-assigned this Sep 11, 2024
@franc6 franc6 added the bug Something isn't working label Sep 11, 2024
@ccMatrix
Copy link
Contributor Author

I didn't have connection_timeout set before moving to 5.0.0 which is where the error came from. Setting it fixes it since then the default is no longer None which is an object it seems to have issues with serializing.

I'm running Home Assistant on a Raspberry Pi 4 via Docker
HA version: 2024.9.1
Docker Image: ghcr.io/home-assistant/raspberrypi4-homeassistant:stable
OS: Ubuntu 22.04 LTS on aarch64 architecture

It is possible that this might be different when on e.g. x86/amd64. Maybe others with the same problem also have it on arm ?

@a351must2
Copy link

Thanks @ccMatrix, I also had to include the reference to connection_timout to get the migration to proceed. I also found that new entities with _2 appended were created and I had to delete theold, and rename the new so they would work with all my templates and automations.

This is what I observed as well. I had to create new ICS_Calendar entries, then I was able to see the old entities listed saying they were no longer provided by ICS Calendar. I was able to delete the old entries and rename the new ones I added to get everything working. I noticed as I was about to roll back to 4.2.0.

@franc6
Copy link
Owner

franc6 commented Sep 11, 2024

I would recommend going back to 4.2.0, anyway for now. I am curious, though it shouldn’t make any difference for serializing, is anyone who sees this running HA on x86-64?

@franc6 franc6 added the question Further information is requested label Sep 11, 2024
@a351must2
Copy link

I would recommend going back to 4.2.0, anyway for now. I am curious, though it shouldn’t make any difference for serializing, is anyone who sees this running HA on x86-64?

Yes, mine is on x86-64

@ccMatrix
Copy link
Contributor Author

I see that in

self.connection_timeout = _GLOBAL_DEFAULT_TIMEOUT

The default value for connection_timeout is set to _GLOBAL_DEFAULT_TIMEOUT which is imported from socket. IF I found the correct library then socket defines this as just object():
https://github.com/python/cpython/blob/e9eedf19c99475b1940bbbbdc8816b51da3968e7/Lib/socket.py#L826

So this might be the reason why it tries to serialize an object?

I didn't 100% understand yet where and how the serialization/conversion from the yaml config to the entity for HA happens in the migration process.

@franc6
Copy link
Owner

franc6 commented Sep 11, 2024

Oh! Great thought! Look at

data[CONF_CONNECTION_TIMEOUT] = None
. I think that’s the problem. Try changing it to use _GLOBAL_DEFAULT_TIMEOUT . If you have the time, feel free to make a PR if you can test it, too. That’s really what it should be, not None, anyway. If you (or someone) can test that, I’d really appreciate it.

@franc6
Copy link
Owner

franc6 commented Sep 11, 2024

I'm blind; I can reproduce this, and the change above doesn't help. If I can steal some time away today to work on this I will.

@ccMatrix
Copy link
Contributor Author

My guess was that the object is initalized into a CalendarData object from the yaml which is then sent to HA for serialization into the entity store. There the connection_timeout is set to _GLOBAL_DEFAULT_TIMEOUT which probably isn't serializable by the json serializer. So you would have to set a different default there. None would work better since that can be serialized to null

franc6 added a commit that referenced this issue Sep 11, 2024
Since we already have a value to indicate if timeout is set, use that and change connection_timeout to be a positive_float.  This fixes the serialization issues, which led to calendars disappearing on restart of HA, and other kinds of havoc.

Also fixed name and unique id properties
@franc6 franc6 mentioned this issue Sep 11, 2024
3 tasks
franc6 added a commit that referenced this issue Sep 11, 2024
Since we already have a value to indicate if timeout is set, use that
and change connection_timeout to be a positive_float. This fixes the
serialization issues, which led to calendars disappearing on restart of
HA, and other kinds of havoc.

Also fixed name and unique id properties

Fixes #151

Description of change:

## Formatting, testing, and code coverage
Please note your pull request won't be accepted if you haven't properly
formatted your source code, and ensured the unit tests are appropriate.
Please note if you are not running on Windows, you can either run the
scripts via a bash installation (like git-bash).

- [X] formatstyle.sh reports no errors
- [X] All unit tests pass (test.sh)
- [X] Code coverage has not decreased (test.sh)
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants