Don't recreate Default product when config database already has products (#1386) - #5000
Merged
bruntib merged 1 commit intoAug 2, 2026
Merged
Conversation
bruntib
approved these changes
Aug 2, 2026
Contributor
|
When I start the sever with a deleted PostgreSQL product database, then server start still fails with some error message. However, that's a different kind, so that could be fixed in a different PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1386
Also fixes #3810 (duplicate)
Problem
If 'Default.sqlite' is deleted while the config database still has
product(s) registered (the old 'Default' entry, or any other product),
the server crashes on startup:
ValueError: Called create_initial_run_database on non-empty config
database -- you shouldn't have done this!
Root cause
'create_default_product' in server_init_start() was decided purely from
whether 'Default.sqlite' exists on disk. It never checked whether the
config database itself already had products. Deleting the sqlite file
alone was enough to re-trigger 'add_initial_run_database()', which
explicitly refuses to run on a non-empty config database.
Fix
Added 'config_db_has_products()', which queries the config database for
any existing product. 'create_default_product' now also requires the
config database to be empty, not just the sqlite file to be missing.
First-time setup (empty DB) is unaffected; an existing-but-file-missing
product now falls through to the normal per-product status/upgrade
handling instead of crashing.
Testing
Added web/server/tests/unit/test_config_db_has_products.py (in-memory
SQLite, real ORM models):
scenario) is correctly detected as non-empty
All tests pass; pycodestyle clean.