fix: A25 + A21 (partiel) — plus d'exception muque, transaction protégée (v7.3.8)
- A25 — 84 `except Exception: pass/…` → `logger.exception("<fonction>")`
(19 fichiers : api_v2 30, dashboard 10, board 7, sites 5, workspace 5,
api_v2_helpers 5, …) ; `logger` ajouté là où il manquait (api_v2_helpers,
sites + `import logging`)
- A25 critique — les `try` autour de `materialize_properties` supprimés dans
`create_collection_v2` ET `apply_db_template_v2` : un échec interrompt la
transaction au lieu de commiter une collection sans schéma
- test `test_collection_rollback_when_materialize_fails` (Bearer v2, monkeypatch
qui lève, assertions : RuntimeError + 0 ligne commitée)
- A21 partiel — `PRAGMA busy_timeout=5000` dans `get_conn()` (point d'entrée
unique) ; commentaire `ponytail:` : le wrapper async + les 510 call sites
restent à migrer module par module
- suite **1028/1028** · `ruff check app tests` OK
This commit is contained in:
@@ -114,6 +114,31 @@ def test_agent_providers_require_admin_and_valid_api_base(client):
|
||||
assert client.post("/api/agent/providers/test", json={"provider": "ollama"}).status_code == 401
|
||||
|
||||
|
||||
def test_collection_rollback_when_materialize_fails(client, monkeypatch):
|
||||
"""A25 : un échec de `materialize_properties` ne doit pas commiter la collection."""
|
||||
import pytest
|
||||
|
||||
from app.services import db_templates
|
||||
|
||||
def boom(*_a, **_k):
|
||||
raise RuntimeError("materialize boom")
|
||||
|
||||
monkeypatch.setattr(db_templates, "materialize_properties", boom)
|
||||
tok = client.post("/api/v1/token").json()["token"]
|
||||
with pytest.raises(RuntimeError):
|
||||
client.post(
|
||||
"/api/v2/collections",
|
||||
json={"name": "Broken", "schema": [{"name": "Title", "type": "title"}]},
|
||||
headers={"Authorization": f"Bearer {tok}"},
|
||||
)
|
||||
|
||||
from app.db import get_conn
|
||||
|
||||
with get_conn() as conn:
|
||||
n = conn.execute("SELECT COUNT(*) FROM collections WHERE name='Broken'").fetchone()[0]
|
||||
assert n == 0, "la collection ne doit pas survivre à un schéma non matérialisé"
|
||||
|
||||
|
||||
def test_exports_and_attachments_require_auth(client):
|
||||
"""A16 : export + pièces jointes = session et `can_view_page` (jamais le contenu)."""
|
||||
pid = client.post("/board/api/pages?title=Secret§ion=Private").json()["id"]
|
||||
|
||||
Reference in New Issue
Block a user