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:
arc53-machine committed 2026-09-17 11:14:34 +01:00
1 parent d70644743b
commit f882ef49a7
46 files changed
+111 -113

No files matched your search

+7 -7
View File
@@ -639,7 +639,7 @@ class WorkflowEngine:
raw_ids = self._resolve_input_artifact_ids(inputs)
if not raw_ids:
return loaded
max_bytes = int(getattr(settings, "SANDBOX_MAX_INPUT_BYTES", 0) or 0)
max_bytes = int(settings.SANDBOX_MAX_INPUT_BYTES or 0)
storage = StorageCreator.get_storage()
# Two inputs whose current versions share a filename would clobber each other at the
# same ``inputs/{name}`` path; track used paths and disambiguate deterministically.
@@ -749,15 +749,15 @@ class WorkflowEngine:
supported = set(supported_types)
supports_images = any(t.startswith("image/") for t in supported)
max_files = int(getattr(settings, "WORKFLOW_NODE_NATIVE_MAX_FILES", 5))
extract_max = int(getattr(settings, "WORKFLOW_NODE_EXTRACT_MAX_FILES", 5))
max_files = int(settings.WORKFLOW_NODE_NATIVE_MAX_FILES)
extract_max = int(settings.WORKFLOW_NODE_EXTRACT_MAX_FILES)
# One wall clock for every blocking parse this node issues. The cap
# above bounds how MANY parses run; this bounds how LONG they take in
# total, so N documents cannot serialize N size-scaled windows.
parse_deadline = time.monotonic() + float(
getattr(settings, "WORKFLOW_NODE_EXTRACT_BUDGET_SECONDS", 900)
settings.WORKFLOW_NODE_EXTRACT_BUDGET_SECONDS
)
max_bytes = int(getattr(settings, "SANDBOX_MAX_INPUT_BYTES", 25 * 1024 * 1024))
max_bytes = int(settings.SANDBOX_MAX_INPUT_BYTES)
# One read-only connection for the whole batch; the resolved-version
# rows are collected, then storage reads happen outside the DB context.
@@ -976,7 +976,7 @@ class WorkflowEngine:
if not user_id:
return None
options = {"output": "markdown", "include_tables": False, "persist": False}
queue = getattr(settings, "DOCUMENT_PARSE_QUEUE", "parsing")
queue = settings.DOCUMENT_PARSE_QUEUE
# OCR cost scales with pages, so the window grows with the document's size
# (floored at DOCUMENT_PARSE_TIMEOUT); the task's per-call time limits are
# raised to match, else the worker would self-terminate mid-parse.
@@ -1084,7 +1084,7 @@ class WorkflowEngine:
"""Return the stricter of the node's requested timeout and the sandbox cap."""
from docsgpt.core.settings import settings
cap = float(getattr(settings, "SANDBOX_EXEC_TIMEOUT", 60))
cap = float(settings.SANDBOX_EXEC_TIMEOUT)
if requested is None:
return cap
try: