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

+6 -6
View File
@@ -124,7 +124,7 @@ def resolve_ocr_backend(requested: Optional[str] = None) -> str:
"""
from docsgpt.core.settings import settings
backend = str(requested or getattr(settings, "OCR_BACKEND", None) or "auto").strip().lower()
backend = str(requested or settings.OCR_BACKEND or "auto").strip().lower()
if backend not in VALID_OCR_BACKENDS:
logger.warning(f"Unknown OCR_BACKEND {backend!r}; using auto")
backend = "auto"
@@ -154,7 +154,7 @@ def resolve_native_ocr_engine(requested: Optional[str] = None) -> str:
"""
from docsgpt.core.settings import settings
engine = str(requested or getattr(settings, "OCR_ENGINE", None) or "tesseract").strip().lower()
engine = str(requested or settings.OCR_ENGINE or "tesseract").strip().lower()
if engine in NATIVE_OCR_ENGINES:
return engine
if engine in VALID_OCR_ENGINES:
@@ -172,7 +172,7 @@ def ocr_min_chars_per_page() -> int:
from docsgpt.core.settings import settings
try:
return int(getattr(settings, "OCR_MIN_CHARS_PER_PAGE", _DEFAULT_MIN_CHARS_PER_PAGE))
return int(settings.OCR_MIN_CHARS_PER_PAGE)
except (TypeError, ValueError):
return _DEFAULT_MIN_CHARS_PER_PAGE
@@ -182,7 +182,7 @@ def render_dpi() -> int:
from docsgpt.core.settings import settings
try:
dpi = int(getattr(settings, "OCR_RENDER_DPI", _DEFAULT_RENDER_DPI))
dpi = int(settings.OCR_RENDER_DPI)
except (TypeError, ValueError):
dpi = _DEFAULT_RENDER_DPI
return max(_MIN_RENDER_DPI, min(_MAX_RENDER_DPI, dpi))
@@ -299,7 +299,7 @@ class TesseractEngine:
else:
from docsgpt.core.settings import settings
configured = str(getattr(settings, "OCR_LANGS", "") or "eng")
configured = str(settings.OCR_LANGS or "eng")
langs = [lang.strip() for lang in configured.split("+") if lang.strip()]
return "+".join(langs) or "eng"
@@ -388,7 +388,7 @@ class DeepseekOcrEngine:
self.url = url or settings.OCR_DEEPSEEK_URL
self.model = model or settings.OCR_DEEPSEEK_MODEL
self.timeout = float(timeout if timeout is not None else getattr(settings, "OCR_DEEPSEEK_TIMEOUT", 300))
self.timeout = float(timeout if timeout is not None else settings.OCR_DEEPSEEK_TIMEOUT)
self.prompt = prompt
self.max_tokens = max_tokens