Skip to content

Don't recreate Default product when config database already has products (#1386) - #5000

Merged
bruntib merged 1 commit into
Ericsson:masterfrom
mmido6039:fix-1386-default-sqlite-removal
Aug 2, 2026
Merged

Don't recreate Default product when config database already has products (#1386)#5000
bruntib merged 1 commit into
Ericsson:masterfrom
mmido6039:fix-1386-default-sqlite-removal

Conversation

@mmido6039

Copy link
Copy Markdown
Contributor

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):

  • empty config DB reports no products (first-time setup still works)
  • a config DB with an existing 'Default' product (the exact bug
    scenario) is correctly detected as non-empty
  • any other registered product also correctly prevents auto-creation

All tests pass; pycodestyle clean.

@mmido6039
mmido6039 requested a review from bruntib as a code owner August 1, 2026 23:21
@bruntib
bruntib merged commit cde30d7 into Ericsson:master Aug 2, 2026
10 checks passed
@bruntib

bruntib commented Aug 2, 2026

Copy link
Copy Markdown
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.

@bruntib bruntib added this to the release 6.29.0 milestone Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants