Bug: on database migration: Unsupported product nesting level detected
See original GitHub issueI updated the homeassistants grocy integration, which updates grocy to 3.1. After this i see this database migration error in grocy:
Error source: /var/www/grocy/services/DatabaseService.php:35
Error message: SQLSTATE[23000]: Integrity constraint violation: 19 Unsupported product nesting level detected (currently only 1 level is supported)
Stack trace: #0 /var/www/grocy/services/DatabaseService.php(35): PDO->exec() #1 /var/www/grocy/services/DatabaseMigrationService.php(63): Grocy\Services\DatabaseService->ExecuteDbStatement() #2 /var/www/grocy/services/DatabaseMigrationService.php(33): Grocy\Services\DatabaseMigrationService->ExecuteSqlMigrationWhenNeeded() #3 /var/www/grocy/controllers/SystemController.php(27): Grocy\Services\DatabaseMigrationService->MigrateDatabase() #4 /var/www/grocy/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(43): Grocy\Controllers\SystemController->Root() #5 /var/www/grocy/vendor/slim/slim/Slim/Routing/Route.php(384): Slim\Handlers\Strategies\RequestResponse->__invoke() #6 /var/www/grocy/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\Routing\Route->handle() #7 /var/www/grocy/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\MiddlewareDispatcher->handle() #8 /var/www/grocy/vendor/slim/slim/Slim/Routing/Route.php(341): Slim\MiddlewareDispatcher->handle() #9 /var/www/grocy/vendor/slim/slim/Slim/Routing/RouteRunner.php(84): Slim\Routing\Route->run() #10 /var/www/grocy/middleware/LocaleMiddleware.php(16): Slim\Routing\RouteRunner->handle() #11 /var/www/grocy/vendor/slim/slim/Slim/MiddlewareDispatcher.php(313): Grocy\Middleware\LocaleMiddleware->__invoke() #12 /var/www/grocy/middleware/AuthMiddleware.php(31): Psr\Http\Server\RequestHandlerInterface@anonymous->handle() #13 /var/www/grocy/vendor/slim/slim/Slim/MiddlewareDispatcher.php(313): Grocy\Middleware\AuthMiddleware->__invoke() #14 /var/www/grocy/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(59): Psr\Http\Server\RequestHandlerInterface@anonymous->handle() #15 /var/www/grocy/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware->process() #16 /var/www/grocy/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(107): Psr\Http\Server\RequestHandlerInterface@anonymous->handle() #17 /var/www/grocy/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\ErrorMiddleware->process() #18 /var/www/grocy/middleware/CorsMiddleware.php(30): Psr\Http\Server\RequestHandlerInterface@anonymous->handle() #19 /var/www/grocy/vendor/slim/slim/Slim/MiddlewareDispatcher.php(313): Grocy\Middleware\CorsMiddleware->__invoke() #20 /var/www/grocy/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Psr\Http\Server\RequestHandlerInterface@anonymous->handle() #21 /var/www/grocy/vendor/slim/slim/Slim/App.php(215): Slim\MiddlewareDispatcher->handle() #22 /var/www/grocy/vendor/slim/slim/Slim/App.php(199): Slim\App->handle() #23 /var/www/grocy/app.php(106): Slim\App->run() #24 /var/www/grocy/public/index.php(45): require_once(‘…’) #25 {main}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
After rolling back to my backup again I was able to identify the 2 offending parent products by opening a copy of the db in sqlitestudio. Simply clearing the “parent product” field in the Grocy UI (which was editable, not greyed out) did not fix the problem… I had to delete the product/item in the UI, restart Home Assistant, and then apply the update to the Grocy add-on.
As you state in your reply to OP, both of the items were originally created by an external app (Pantry Party android app), but I’m pretty sure it was in Grocy v3.0.0. The child/parent products were also weird combinations (for instance tortillas as child to coffee) that I wouldn’t have done on purpose.
I’ve added a workaround to also handle having unsupported parent/child product nesting levels.
If you want to have this now, replace the file
migrations/0130.sql
with that one and the upgrade will work. (It simply clears the “Parent product” field for any nesting level > 1.)Just for reference and reproducibility, here is a
v3.0.1
(demo) database which has this problem (manually created -Chocolate
, which is already a parent forMilk Chocolate
andDark Chocolate
, is a child ofCookies
at the same time):grocy_v3.0.1_unsupported_product_nesting_level.zip
And only to note that again:
v3.0.0
v3.0.0
this is also enforced via the API/backend