Skip to content

Commit 9e42a35

Browse files
fix: ensure database settings printed in startup logging (#1316)
We have detected issues with the current code in startup logging where the database settings are not printed. The current code has a bug where we assumed the databases object would be a `box` object provided by dynaconf, but it is actually a dict, so it never will have attributes. This code fixes the issue and ensures the database settings are printed. Signed-off-by: Alex <[email protected]>
1 parent 77a0b8e commit 9e42a35

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/aap_eda/utils/logging.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ def startup_logging(logger: logging.Logger) -> None:
101101

102102
# Database settings
103103
unconditional_logger.log(" Default database:")
104+
if not settings.DATABASES or not settings.DATABASES.get("default"):
105+
logger.error(
106+
"Expected setting DATABASES not found or empty",
107+
)
104108
for setting in ["USER", "HOST", "PORT", "OPTIONS"]:
105-
if hasattr(settings.DATABASES["default"], setting):
106-
unconditional_logger.log(
107-
f" {setting}: "
108-
f"{getattr(settings.DATABASES['default'], setting)}",
109-
)
110-
109+
value = settings.DATABASES["default"].get(setting)
110+
unconditional_logger.log(f" {setting}: {value}")
111111
# Resource server is relevant but can contain sensitive information
112112
resource_server = settings.RESOURCE_SERVER.get("URL")
113113
unconditional_logger.log(f" Resource server: {resource_server}")

tests/integration/test_logging.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def test_http_startup_logging(caplog_factory, module):
2020

2121
assert "Starting eda-server" in caplog.text
2222

23+
# hardcoded value to not depends on settings
24+
# and be able to handle unexpected lookups
25+
assert "HOST: localhost" in caplog.text
26+
2327

2428
def test_worker_startup_logs():
2529
"""

0 commit comments

Comments
 (0)