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

+4 -4
View File
@@ -53,7 +53,7 @@ def _resolve_batch_size() -> int:
Returns:
Chunks per embed request, always >= 1.
"""
raw = getattr(settings, "EMBEDDINGS_BATCH_SIZE", None)
raw = settings.EMBEDDINGS_BATCH_SIZE
# Explicit type check rather than a bare ``int(raw)``: ``int(MagicMock())``
# succeeds and yields 1, which would silently drop ingest back to the
# per-chunk behaviour this batching replaces.
@@ -326,7 +326,7 @@ def embed_and_store_documents(
store = VectorCreator.create_vectorstore(
settings.VECTOR_STORE,
source_id=source_id,
embeddings_key=os.getenv("EMBEDDINGS_KEY"),
embeddings_key=settings.EMBEDDINGS_KEY,
)
loop_start = resume_index
else:
@@ -336,7 +336,7 @@ def embed_and_store_documents(
settings.VECTOR_STORE,
docs_init=[docs[0]],
source_id=source_id,
embeddings_key=os.getenv("EMBEDDINGS_KEY"),
embeddings_key=settings.EMBEDDINGS_KEY,
)
# Record the seeded chunk so single-doc ingests don't fail
# ``assert_index_complete`` — the loop never runs for
@@ -351,7 +351,7 @@ def embed_and_store_documents(
store = VectorCreator.create_vectorstore(
settings.VECTOR_STORE,
source_id=source_id,
embeddings_key=os.getenv("EMBEDDINGS_KEY"),
embeddings_key=settings.EMBEDDINGS_KEY,
)
# Only wipe the index on a fresh run — a resume must keep the
# chunks that earlier attempts already embedded.