mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-25 18:40:06 -04:00
Keep the API's logging when migrating at startup (#782)
WROLPi runs alembic migrations in-process at startup (db_bootstrap). alembic/env.py called fileConfig unconditionally, which replaced the root handlers, set the root level to WARN, and disabled every logger that already existed, so the API's logs went quiet after any startup migration until the next restart. env.py now configures logging only when alembic runs from its command line (cmd_opts is set). This also caused an order-dependent test failure: test_jobs's capture test failed whenever test_db_bootstrap ran first in the same worker. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2b2361ed64
commit
b742a4a25f
2 changed files with 19 additions and 3 deletions
|
|
@ -6,9 +6,10 @@ from alembic import context
|
|||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
fileConfig(config.config_file_name)
|
||||
# Configure logging only for the alembic command line. WROLPi also migrates in-process at startup
|
||||
# (db_bootstrap), where fileConfig would replace the API's handlers and disable its existing loggers.
|
||||
if config.cmd_opts is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
|
|
|
|||
|
|
@ -17,6 +17,21 @@ def permissive_sqlite_floor():
|
|||
yield
|
||||
|
||||
|
||||
def test_migration_keeps_logging(test_directory):
|
||||
"""WROLPi migrates in-process at startup; alembic must not reconfigure the API's logging."""
|
||||
import logging
|
||||
|
||||
existing = logging.getLogger('wrolpi.test.existing_logger')
|
||||
root_handlers = list(logging.getLogger().handlers)
|
||||
root_level = logging.getLogger().level
|
||||
|
||||
assert db_bootstrap.ensure_db() is True
|
||||
|
||||
assert existing.disabled is False
|
||||
assert logging.getLogger().handlers == root_handlers
|
||||
assert logging.getLogger().level == root_level
|
||||
|
||||
|
||||
def test_ensure_db_creates_and_migrates(test_directory):
|
||||
"""With no database file, ensure_db creates it and migrates to head."""
|
||||
db_file = get_db_file()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue