Fail closed when wizard state segments is not a mapping - #128
Merged
Merged
Conversation
GET /api/segments called .get on a list or scalar under .docgen-state.json segments and raised AttributeError. Require a JSON object of per-id objects; POST /api/state rejects the same payload. Co-authored-by: jmjava <jmjava@gmail.com>
Co-authored-by: jmjava <jmjava@gmail.com>
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.
Problem
load_stateaccepts any JSON object.GET /api/segmentsthen doesstate.get("segments", {}).get(seg_id, {}). A list, string, or per-id non-object undersegmentsraisesAttributeError.POST /api/statewrites that payload unchanged.Corrupt JSON / a non-object root still reset to
{"segments": {}}so a broken file does not brick the wizard.Change
When
segmentsis present, it must be a JSON object whose values are objects. Missing / nullsegmentsstill means{}.GET /api/stateandGET /api/segmentsreturn 500 withWizardError(not a traceback)POST /api/statereturns 400 for a non-object body or invalidsegments, and does not write the fileTests
Local:
ruff check src/ tests/green;pytest tests/741 passed, 1 skipped;docgen benchmarkmeetssrc/docgen/benchmark_data/baseline.json(no--update-baseline).load_statestill resets corrupt JSONsegmentsand per-id non-objects raisesegmentsbecomes{}Out of scope
except Exceptionaroundnarration_topic_label