Skip to content

Fix inline-snapshot compatibility#3506

Merged
koxudaxi merged 1 commit into
mainfrom
fix-inline-snapshot-compat
Jun 30, 2026
Merged

Fix inline-snapshot compatibility#3506
koxudaxi merged 1 commit into
mainfrom
fix-inline-snapshot-compat

Conversation

@koxudaxi

@koxudaxi koxudaxi commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Fixes: #3505

Summary by CodeRabbit

  • Bug Fixes
    • Improved external-file inline-snapshot comparisons with line-ending normalization, unified diffs in failures, and correct create/fix behavior for missing or mismatched snapshot content.
  • Tests
    • Added broader unit coverage for the external-file assertion helpers, including active vs inactive inline-snapshot states, missing files, storage-lookup errors, and validation of recorded snapshot updates.
  • Chores
    • Updated the inline-snapshot test dependency version constraint.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 420ad225-0961-40fe-b7ec-a9f88fbfc828

📥 Commits

Reviewing files that changed from the base of the PR and between a583915 and bfc24d6.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock, !**/*.lock and included by none
📒 Files selected for processing (3)
  • pyproject.toml
  • tests/conftest.py
  • tests/test_conftest_helpers.py
✅ Files skipped from review due to trivial changes (1)
  • pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/conftest.py
  • tests/test_conftest_helpers.py

📝 Walkthrough

Walkthrough

Raises the inline-snapshot test dependency floor, updates the shared external-file assertion helper to use snapshot lookup with create/fix gating, and adds tests covering active, inactive, missing, and mismatched external snapshot files.

Changes

Inline-snapshot API compatibility update

Layer / File(s) Summary
Dependency and import update
pyproject.toml, tests/conftest.py
inline-snapshot is bumped to >=0.34.2, and get_snapshot_value is added to the shared conftest imports.
External-file assertion rewrite
tests/conftest.py
String inputs use structural matching with normalized line endings and diff output; non-string inputs now read the prior snapshot value, treat lookup failures as missing, and gate create/fix behavior on update flags.
External-file helper tests
tests/test_conftest_helpers.py
Tests cover inline snapshot active/inactive loading, missing external files with and without create, StorageLookupError as missing, and mismatch handling with and without fix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐇 I hopped through snapshots, old and new,
A version bump made tests run true.
Create and fix now dance in time,
With diffs and flags that simply rhyme.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main compatibility fix in the pull request.
Linked Issues check ✅ Passed The refactor and added tests address the ExternalFile._load_value compatibility break and restore expected test behavior.
Out of Scope Changes check ✅ Passed The changes stay focused on inline-snapshot compatibility, dependency bounds, and supporting tests.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-inline-snapshot-compat

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@koxudaxi koxudaxi marked this pull request as ready for review June 30, 2026 16:45
@github-actions

Copy link
Copy Markdown
Contributor

📚 Docs Preview: https://pr-3506.datamodel-code-generator.pages.dev

@codspeed-hq

codspeed-hq Bot commented Jun 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 10.13%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 1 improved benchmark
✅ 10 untouched benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_perf_graphql_style_pydantic_v2 827 ms 751 ms +10.13%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix-inline-snapshot-compat (bfc24d6) with main (cb192dd)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cb192dd) to head (bfc24d6).

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #3506    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          153       153            
  Lines        33755     33896   +141     
  Branches      3958      3967     +9     
==========================================
+ Hits         33755     33896   +141     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@koxudaxi koxudaxi force-pushed the fix-inline-snapshot-compat branch from c5f6c5f to 149e46b Compare June 30, 2026 16:50

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/conftest.py (2)

614-650: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: deduplicate the mismatch error construction.

The hint/diff/msg/raise block at Lines 618-621 (string branch) and Lines 647-650 (non-string branch) is identical. Extracting a small local helper would reduce repetition.

🤖 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 614 - 650, The mismatch error construction is
duplicated in both the string and non-string branches of the snapshot assertion
logic, so factor the shared hint/diff/msg/raise sequence into a small local
helper inside the snapshot comparison flow. Keep the existing behavior in the
function that handles normalized content and expected values, and reuse the
helper from both branches to avoid repeating the same error-building code.

630-646: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

assert used for the inline-snapshot recording side effect is fragile under python -O.

Lines 633 and 645 rely on expected == normalized_content to trigger inline-snapshot's __eq__ materialization in create/fix mode, then wrap it in assert. When tests run with python -O (or PYTHONOPTIMIZE), assert statements are stripped, so the comparison never executes and missing/mismatched external files would silently not be created/updated. Consider executing the comparison as a plain statement (and asserting on a captured result if you still want the check).

♻️ Suggested change
-                if update_flags.create:
-                    # Let inline-snapshot materialize missing external files only in create mode.
-                    assert expected == normalized_content
-                    return
+                if update_flags.create:
+                    # Let inline-snapshot materialize missing external files only in create mode.
+                    matched = expected == normalized_content
+                    assert matched
+                    return

(and likewise for the fix-mode branch at Line 645)

🤖 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 630 - 646, The create/fix branches in the
inline-snapshot handling rely on an `assert` to trigger `expected ==
normalized_content`, but that side effect is stripped under optimized Python
runs. Update the logic in the snapshot comparison block to execute the equality
comparison as a plain statement in both the create-mode and fix-mode paths,
using the existing `expected`, `normalized_content`, `update_flags.create`, and
`update_flags.fix` flow; if you still need a validation check, capture the
comparison result separately instead of depending on `assert`.
🤖 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 614-650: The mismatch error construction is duplicated in both the
string and non-string branches of the snapshot assertion logic, so factor the
shared hint/diff/msg/raise sequence into a small local helper inside the
snapshot comparison flow. Keep the existing behavior in the function that
handles normalized content and expected values, and reuse the helper from both
branches to avoid repeating the same error-building code.
- Around line 630-646: The create/fix branches in the inline-snapshot handling
rely on an `assert` to trigger `expected == normalized_content`, but that side
effect is stripped under optimized Python runs. Update the logic in the snapshot
comparison block to execute the equality comparison as a plain statement in both
the create-mode and fix-mode paths, using the existing `expected`,
`normalized_content`, `update_flags.create`, and `update_flags.fix` flow; if you
still need a validation check, capture the comparison result separately instead
of depending on `assert`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b057567c-359c-4c39-8d18-a9dabe022767

📥 Commits

Reviewing files that changed from the base of the PR and between cb192dd and c5f6c5f.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock, !**/*.lock and included by none
📒 Files selected for processing (3)
  • pyproject.toml
  • tests/conftest.py
  • tests/test_conftest_helpers.py

@koxudaxi koxudaxi force-pushed the fix-inline-snapshot-compat branch from 149e46b to a583915 Compare June 30, 2026 16:57
@koxudaxi koxudaxi force-pushed the fix-inline-snapshot-compat branch from a583915 to bfc24d6 Compare June 30, 2026 17:03
@koxudaxi koxudaxi merged commit 2dae227 into main Jun 30, 2026
60 checks passed
@koxudaxi koxudaxi deleted the fix-inline-snapshot-compat branch June 30, 2026 17:19
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR only modifies test infrastructure: it bumps the inline-snapshot test/dev dependency (>=0.31.1 → >=0.34.2) in pyproject.toml and uv.lock, refactors a test helper in tests/conftest.py to adapt to the new inline-snapshot API (replacing the removed private _load_value() with the public get_snapshot_value), and adds new helper tests. None of these affect the package's runtime code, CLI options, Python API, Jinja2 templates, generated code output, default behavior, supported Python versions, or error handling. inline-snapshot is a test-only dependency, so it does not impact end users. No removed public options, parameters, classes, enums, or functions appear in the diff.


This analysis was performed by Claude Code Action

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.66.1

This PR is now available in the latest release. See the release notes for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: ExternalFile._load_value() missing 1 required positional argument: 'which'

1 participant