fix(sparql): POST 403 → fallback GET (WAF/Virtuoso, caso Senato) - #447
Merged
Conversation
Il plugin considerava 'ok' qualsiasi risposta HTTP (is_ok = response presente, err None) → il fallback GET non scattava mai su endpoint che rifiutano POST con 403 (es. dati.senato.it — accetta solo GET). Fix: - POST ok solo se status < 400 - fallback GET solo su 4xx (WAF/Virtuoso rifiutano POST, accettano GET) - 5xx solleva DownloadError con codice HTTP esplicito (non mascherare l'errore server col fallback) Test: test_sparql_fetch_post_403_falls_back_to_get (regressione, caso dati.senato.it reale). 25/25 sparql plugin + 9 contracts pass.
Il fix mypy del CI segnalava 'Item None of ResponseLike|None has no attribute text' sul raise 5xx. Gestito il caso response=None.
7 tasks
Gabrymi93
added a commit
that referenced
this pull request
Aug 4, 2026
… GET 5xx (#448) Completa il fix #447 (POST 403 → GET fallback) con i casi che il docstring prometteva ma il codice non copriva: - POST con errore di rete/timeout (post_status None) → prova GET fallback - GET fallback che restituisce 5xx → DownloadError esplicito con status Test: 4 casi coperti (403→GET, timeout→GET, GET 500→errore, POST 500→errore). 26/26 pass, mypy ok, ruff ok. End-to-end sul Senato reale: OK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sintesi
Fix del plugin SPARQL: il fallback GET non scattava mai su endpoint che rifiutano il POST con 4xx.
is_okconsiderava "ok" qualsiasi risposta HTTP (response presente, err None) → un 403 con body HTML veniva salvato come CSV valido.Scoperto lavorando su
senato-ddl(issue dataset-incubator #781):dati.senato.itaccetta solo GET (POST → 403), e il plugin falliva perché il 403 non attivava il fallback documentato ("Se POST fallisce (403, timeout), prova GET").Contesto collegato
Cosa cambia
Impatto su contratti pubblici
dataset.yml(nuovo campo, cambio obbligatorietà)Nessun contratto pubblico toccato — comportamento interno del fetch.
Dettaglio
Prima (bug):
Dopo (fix):
DownloadErrorcon codice HTTP esplicito (il fallback non deve mascherare un errore server reale)Verifica
pytest tests/test_sparql_plugin.py tests/test_contracts.py # 34 passed ruff check toolkit/plugins/sparql.py tests/test_sparql_plugin.pyTest nuovo:
test_sparql_fetch_post_403_falls_back_to_get— regressione sul caso reale dati.senato.it (POST 403 → GET fallback → CSV valido). Verifica end-to-end:toolkit run raw -c candidates/senato-ddl/dataset.ymlpassa sul Senato reale.Note
_parse_responsesollevava errore sul body non-SPARQL → ora errore esplicito con codice HTTP (stessa semantica, messaggio più chiaro)test_sparql_fetch_http_error(500 → DownloadError "HTTP 500") continua a passare