Closed mstovenour closed 2 years ago
recorder documentation recorder source (message by IssueLinks)
Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (recorder
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
FWIW, I encountered the same problem upgrading from 2021.2.3 to 2021.12. Also using Postgres. Relevant logs at https://gist.github.com/wfscot/c2bb9b0d87fc563900102ade8b54638a.
Let me know if you need any more info.
@mstovenour Can you verify the patch in #65680 please?
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment š This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
The problem
Every time I start home assistant core I receive a traceback indicating an error with a column name that already exists while performing schema migration for recorder. I see that there was a previous issue reported #60488 like this one which includes a fix that I have. However in reviewing both my traceback and the traceback of the previous issue it seems that the provided fix was not complete. There are two try/except blocks and, while the error will happen in both places, it happens first at line 200 which you can see from both my traceback below and the traceback in issue #60488.
I tried some simple things to catch / ignore that error in the first ALTER however I ran into issues with the overall transaction rollback. I'm not sure exactly how to fix the issue. I think that multi-table ALTER at line 200 needs to be wrapped in its own transaction so the error handler can roll it back. Also, this particular error is caught by neither InternalError nor OperationalError. I had to add a generic "except Exception as err:" handler to catch this error.
I then tried commenting out the entire first ALTER and changing the second exception handler to "except Exception as err:". This also did not work because the failed ALTER left the transaction in a bad state. After adding a nested transaction, the migration was able to complete. I use PostgreSQL; don't know if all the supported databases allow nested transactions so this might not be a good long term solution. I also think that something like this could wrap the first ALTER but I didn't try that.
Below is the hack I used to get the database migrated:
What version of Home Assistant Core has the issue?
core-2021.12.5
What was the last working version of Home Assistant Core?
core-2021.6.6
What type of installation are you running?
Home Assistant Container
Integration causing the issue
Recorder
Link to integration documentation on our website
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Additional information
Running PostgreSQL