fix: re-vérifier db_path.exists() dans le handler et assertion return value (#78)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Colin Maudry
2026-06-12 13:50:57 +02:00
parent bba53d81e1
commit fa2709b38c
2 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ def _ensure_database() -> Path:
else: else:
logger.debug("Base de données déjà disponible et à jour.") logger.debug("Base de données déjà disponible et à jour.")
except Exception as e: except Exception as e:
if db_exists: if db_exists and db_path.exists():
logger.error( logger.error(
f"Bootstrap données KO ({e}). " f"Bootstrap données KO ({e}). "
f"Réutilisation du DuckDB existant : {db_path}" f"Réutilisation du DuckDB existant : {db_path}"
+2 -1
View File
@@ -340,7 +340,8 @@ def test_ensure_database_reuses_db_when_build_raises(tmp_path, monkeypatch):
monkeypatch.setenv("DATA_FILE_PARQUET_PATH", "http://unreachable") monkeypatch.setenv("DATA_FILE_PARQUET_PATH", "http://unreachable")
monkeypatch.setattr(db, "should_rebuild", lambda *a, **k: True) monkeypatch.setattr(db, "should_rebuild", lambda *a, **k: True)
monkeypatch.setattr(db, "build_database", _raise) monkeypatch.setattr(db, "build_database", _raise)
db._ensure_database() # ne doit pas lever result = db._ensure_database() # ne doit pas lever
assert result == dbf
assert dbf.read_bytes() == b"existing" assert dbf.read_bytes() == b"existing"