mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-17 10:13:57 +00:00
refactor: read settings directly instead of getattr with a second default
About 85 call sites read a setting as getattr(settings, "NAME", fallback), each carrying its own copy of the default. Every one of those names is a field with a default on the model, so the fallback could never apply to the real settings object; it only masked drift. Two had drifted: - OPENAI_PROMPT_CACHE_KEY defaults to True on the model but the reader fell back to False, and two test stubs relied on that. - SharePoint's MICROSOFT_AUTHORITY fallback to https://login.microsoftonline.com/<tenant> never fired, because the attribute always exists (as None), so MSAL got authority=None. The connector now derives the tenant authority when the setting is unset, as its test always assumed. Four places read EMBEDDINGS_KEY straight from os.environ, skipping the "None"/"" normalisation the model applies; they read the setting now. Test stubs that replaced a module's settings with a SimpleNamespace list every setting the code under test reads.
This commit is contained in:
1 parent
d70644743b
commit
f882ef49a7
46 files changed
+111
-113
No files matched your search
@@ -96,7 +96,7 @@ def _release_boot_only_embeddings(log: logging.Logger) -> None:
|
||||
|
||||
if settings.EMBEDDINGS_BASE_URL:
|
||||
return
|
||||
if getattr(settings, "EMBEDDINGS_DELEGATE_TO_WORKER", False) is not True:
|
||||
if settings.EMBEDDINGS_DELEGATE_TO_WORKER is not True:
|
||||
return
|
||||
|
||||
import gc
|
||||
@@ -144,8 +144,8 @@ def ensure_vector_schema(*, logger: Optional[logging.Logger] = None) -> None:
|
||||
)
|
||||
return
|
||||
|
||||
dsn = getattr(settings, "PGVECTOR_CONNECTION_STRING", None)
|
||||
if not dsn and getattr(settings, "POSTGRES_URI", None):
|
||||
dsn = settings.PGVECTOR_CONNECTION_STRING
|
||||
if not dsn and settings.POSTGRES_URI:
|
||||
from docsgpt.core.db_uri import normalize_pgvector_connection_string
|
||||
|
||||
dsn = normalize_pgvector_connection_string(settings.POSTGRES_URI)
|
||||
@@ -172,7 +172,7 @@ def ensure_vector_schema(*, logger: Optional[logging.Logger] = None) -> None:
|
||||
|
||||
dim: Optional[int] = dimension_for(settings.EMBEDDINGS_NAME)
|
||||
|
||||
graph_enabled = bool(getattr(settings, "GRAPHRAG_ENABLED", False))
|
||||
graph_enabled = bool(settings.GRAPHRAG_ENABLED)
|
||||
started = time.monotonic()
|
||||
# A plain connection, never the store's pool: this can run pre-fork under
|
||||
# ``gunicorn --preload``, and an inherited pooled socket is a broken one.
|
||||
|
||||
Reference in new issue
Block a user