Guard mutable generation inputs#3394
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR prevents input mutation in the JSON Schema parser by excluding parser-owned "self" metadata from validation inputs without mutating originals, adds a test context manager to detect input mutations, updates integration test helpers to use the guard, and adds regression and unit tests to verify no mutations occur. ChangesInput Mutation Prevention
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
📚 Docs Preview: https://pr-3394.datamodel-code-generator.pages.dev |
Merging this PR will not alter performance
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/conftest.py (1)
707-711: ⚡ Quick winConsider
isinstancefor clarity.While the match statement is correct, a simpler alternative would be more readable for this type check.
♻️ Simpler alternative
def _tracks_mutation(value: object) -> bool: - match value: - case dict() | list(): - return True - return False + return isinstance(value, (dict, list))🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/conftest.py` around lines 707 - 711, The helper _tracks_mutation currently uses a match statement for a simple type check; replace the match with a direct isinstance check (e.g., return isinstance(value, (dict, list))) inside the _tracks_mutation function to make the intent clearer and more concise while preserving behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/conftest.py`:
- Around line 707-711: The helper _tracks_mutation currently uses a match
statement for a simple type check; replace the match with a direct isinstance
check (e.g., return isinstance(value, (dict, list))) inside the _tracks_mutation
function to make the intent clearer and more concise while preserving behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: eb8dd47e-cb39-4af7-abd5-2d5192ffd440
📒 Files selected for processing (7)
src/datamodel_code_generator/parser/jsonschema.pytests/conftest.pytests/main/conftest.pytests/main/jsonschema/test_main_jsonschema.pytests/main/protobuf/test_main_protobuf.pytests/main/test_main_general.pytests/test_conftest_helpers.py
c22cf41 to
c2745d0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3394 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 138 138
Lines 29372 29426 +54
Branches 3512 3514 +2
=========================================
+ Hits 29372 29426 +54
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
84bebc1 to
bed3861
Compare
bed3861 to
a4ea7ff
Compare
Breaking Change AnalysisResult: No breaking changes detected Reasoning: PR #3394 ("Guard mutable generation inputs") is a defensive internal refactor of the JsonSchemaObject parser class to avoid mutating caller-provided input dicts/cached parsed data. The only non-test source change is src/datamodel_code_generator/parser/jsonschema.py: it adds defensive copies (values = dict(values)), moves extra-field collection from init into a mode="before" validator that returns a new dict, replaces the custom init with model_post_init, adjusts validate_items to use This analysis was performed by Claude Code Action |
|
🎉 Released in 0.64.0 This PR is now available in the latest release. See the release notes for details. |
No description provided.