Spaces:
Build error
Fix duplicate get_dossier_output_dir() definition in config/settings.py
Browse filesRoot cause: an earlier delivery script was accidentally re-run after a
'git checkout -b' failed with branch-already-exists (bash does not stop
on a non-&&-chained command failure). That script's edit anchor matched
only the function's own unchanged body, not anything after it, so the
second run found the same anchor again and inserted a second, verbatim
copy of the function immediately after the first.
Trigger condition: any second invocation of that specific delivery step
against a repo where it had already succeeded once.
Blast radius: definition-order only. Python's later def silently
shadowed the earlier one; both bodies were byte-identical, so every
call site kept calling the same function with the same behavior. No
functional bug reached any user -- this is a code-hygiene / future-
drift-risk fix.
Verified (in sandbox before delivery): python -m py_compile succeeds;
AST-parsed the module and confirmed exactly one top-level FunctionDef
named get_dossier_output_dir (was 2, now 1); imported the module
directly and called get_dossier_output_dir() in both web mode and
BHARATGRAPH_DESKTOP_MODE=true, confirming both return the same paths
as before the fix.
- config/settings.py +0 -34
|
@@ -76,40 +76,6 @@ def get_dossier_output_dir() -> str:
|
|
| 76 |
return os.path.join(_project_root, "data", "processed")
|
| 77 |
|
| 78 |
|
| 79 |
-
def get_dossier_output_dir() -> str:
|
| 80 |
-
"""Absolute base directory generated dossiers/reports are written to
|
| 81 |
-
and may be served from.
|
| 82 |
-
|
| 83 |
-
P-1 fix, centralized here because this exact path was previously
|
| 84 |
-
hardcoded/recomputed independently in THREE places that all need to
|
| 85 |
-
agree for the export flow to work at all:
|
| 86 |
-
- ai/dossier_generator.py's generate() computed its own
|
| 87 |
-
<project_root>/data as a path-traversal allowlist (H-07/CodeQL
|
| 88 |
-
fix) and joined output_dir onto <project_root> directly.
|
| 89 |
-
- api/routes/export.py passed the literal string "data/processed"
|
| 90 |
-
as that function's output_dir argument.
|
| 91 |
-
- api/routes/export.py ALSO independently recomputed
|
| 92 |
-
<project_root>/data/processed as ITS OWN separate, independent
|
| 93 |
-
path-traversal allowlist (a second H-07/CodeQL fix) to validate
|
| 94 |
-
the path generate() handed back, before serving the file.
|
| 95 |
-
These three were already subtly inconsistent with each other before
|
| 96 |
-
any desktop-mode change: the first allowed anything under
|
| 97 |
-
<project_root>/data/ (e.g. data/samples), while the second allowed
|
| 98 |
-
only <project_root>/data/processed specifically -- benign only
|
| 99 |
-
because output_dir is never actually varied by any real caller
|
| 100 |
-
today. Unifying all three onto this single function fixes that
|
| 101 |
-
latent inconsistency and means a future desktop-mode change to
|
| 102 |
-
where dossiers live can never desync between the two independent
|
| 103 |
-
security guards that gate the export endpoint.
|
| 104 |
-
Web-deployment behavior is unchanged when BHARATGRAPH_DESKTOP_MODE
|
| 105 |
-
is unset -- same exact <project_root>/data/processed as before.
|
| 106 |
-
"""
|
| 107 |
-
if os.getenv("BHARATGRAPH_DESKTOP_MODE", "").lower() == "true":
|
| 108 |
-
return str(get_app_data_dir() / "reports")
|
| 109 |
-
_project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 110 |
-
return os.path.join(_project_root, "data", "processed")
|
| 111 |
-
|
| 112 |
-
|
| 113 |
def _local_config_path() -> Path:
|
| 114 |
return get_app_data_dir() / "config.json"
|
| 115 |
|
|
|
|
| 76 |
return os.path.join(_project_root, "data", "processed")
|
| 77 |
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
def _local_config_path() -> Path:
|
| 80 |
return get_app_data_dir() / "config.json"
|
| 81 |
|