-
Notifications
You must be signed in to change notification settings - Fork 0
Development #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development #31
Changes from all commits
56e44f8
82db2b0
579683d
fad6d1a
a12de82
5d79afe
0f3af89
d5d90f6
cbf5fcd
5a5d1d5
207ba9b
76b9912
366b640
ebc7bb7
be9a086
3fc9146
914b789
938886f
7737a2f
3ea0d45
ee4de2a
3ae0527
25dc303
730dc88
bb266bd
7d70a13
d1f450d
5436727
d8c850e
1405787
1ad53b1
3956aed
a0b1f82
a2d0cea
6adf5b1
57df8ef
6bbabff
7672520
d56e12e
5aca8cf
f0cb455
dd0ffab
4f534c8
9095db5
979acca
008f0e0
c09bdcc
1cb53f6
ee60426
56967e2
cfcf2dd
1aa6813
5844084
4a6a8e5
693bfbc
326928e
a80e583
69800d3
365ef8e
61d9dcf
046c52f
7b33d13
638fb4e
59a7722
4a09f0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,18 +86,27 @@ def get_database_session(): | |
| yield session | ||
|
|
||
| def get_settings() -> dict: | ||
| """Get application settings from database""" | ||
| """Get application settings from database, merged with defaults for any missing keys""" | ||
| import json | ||
| try: | ||
| # Load defaults | ||
| defaults = {} | ||
| if os.path.exists(DEFAULTS_PATH): | ||
| with open(DEFAULTS_PATH, 'r', encoding='utf-8') as f: | ||
| defaults = json.load(f) | ||
|
|
||
| with Session(engine) as session: | ||
| row = session.exec(select(Setting).where(Setting.key == "settings")).first() | ||
| if row: | ||
| settings = json.loads(row.value_json) | ||
| # Merge defaults with loaded settings (settings take precedence) | ||
| # This ensures new settings are available even in old databases | ||
| merged = {**defaults, **settings} | ||
| logger.info(f"Loaded settings from database: {DB_PATH}") | ||
| return settings | ||
| return merged | ||
| else: | ||
| logger.error("No settings found in database!") | ||
| return {} | ||
| return defaults | ||
|
Comment on lines
+92
to
+109
|
||
| except Exception as e: | ||
| logger.error(f"Error loading settings: {e}") | ||
| return {} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -4,13 +4,20 @@ | |||
| """ | ||||
| import pytest | ||||
| import asyncio | ||||
| import os | ||||
|
||||
| import os |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,4 @@ | |
| This file is automatically updated during CI/CD builds | ||
| """ | ||
|
|
||
| __version__ = "1.3.0" | ||
| __version__ = "1.3.1" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shallow merge strategy
{**defaults, **settings}may not properly handle nested settings dictionaries. For example, if a new nested key is added totts.monsterttsin defaults but the database already has attsobject, the nested default keys won't be merged - the entire databasettsobject will override the defaults. Consider using a deep merge function to ensure nested settings defaults are properly merged.