Skip to content

Remove the import caches and their clearing - #5174

Merged
Koudai Aono (koxudaxi) merged 4 commits into
mainfrom
rp15b-import-caches
Oct 23, 2026
Merged

Koudai Aono (koxudaxi) merged 4 commits into
mainfrom
rp15b-import-caches

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Generated model imports now reflect the current model and field state after changes, including import aliasing and model transformations.
  • Refactor
    • Import-cache retention and invalidation behavior has been removed; imports are recalculated when read.
    • The existing import-cache clearing method remains available for compatibility but is deprecated and has no effect.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T23:35:40.330387Z 34e3355 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 316c564d5008fe2ad4ff541680bb3427e55a75d1 and 34e3355b6e6051e96d520cef6e01b6897058e95d.

⛔ Files ignored due to path filters: 16
  • docs/llms-full.txt is excluded by none and included by none
  • tests/data/expected/main/builtin_import_cache_retention.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/builtin_import_cache_unique_items_unhashable.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/custom_import_cache_cross_module_history.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/custom_import_cache_inherited_enum_history.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/generation_platform/MsgspecStruct.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/generation_store_usage/checker_follows_aliases_through_rebinding_and_entries.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/generation_store_usage/checker_forgets_skipped_names_when_they_are_rebound.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/generation_store_usage/checker_reports_fact_presentation_and_cache_writes_in_parser_code.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/generation_store_usage/checker_scans_model_hooks_helpers_and_caches.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/pipeline/tables_follow_the_rules.provisional_reads.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/pipeline/trace_matches_golden[jsonschema].txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/pipeline/trace_matches_golden[msgspec-tree-reuse].txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/pipeline/trace_matches_golden[openapi-modules].txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/pipeline/trace_matches_golden[renamed-sequence-roots].txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/pipeline/trace_matches_golden[typed-dict-import-overrides].txt is excluded by !tests/data/**/*.txt and included by none
📒 Files selected for processing: 27
  • docs/architecture.md
  • scripts/generation_store_allowlist.toml
  • src/datamodel_code_generator/_parse_memo.py
  • src/datamodel_code_generator/model/base.py
  • src/datamodel_code_generator/model/pydantic_v2/base_model.py
  • src/datamodel_code_generator/model/pydantic_v2/dataclass.py
  • src/datamodel_code_generator/model/pydantic_v2/root_model.py
  • src/datamodel_code_generator/parser/_facts.py
  • src/datamodel_code_generator/parser/_pass_decls.py
  • src/datamodel_code_generator/parser/_passes/_shared.py
  • src/datamodel_code_generator/parser/avro.py
  • src/datamodel_code_generator/parser/base.py
  • src/datamodel_code_generator/parser/generation.py
  • tests/assert_helper_allowlists.py
  • tests/data/expected/main/custom_import_cache_alias_invalidation.py
  • tests/data/expected/main/custom_import_cache_generic_base.py
  • tests/data/expected/main/custom_import_cache_invalidation.py
  • tests/data/expected/main/custom_import_cache_unique_items.py
  • tests/main/test_main_general.py
  • tests/main/test_main_general.refs
  • tests/model/test_base.py
  • tests/parser/test_base.py
  • tests/parser/test_fact_finality.py
  • tests/parser/test_generation.py
  • tests/parser/test_generation_store_usage.py
  • tests/parser/test_model_construction_capabilities.py
  • tests/parser/test_python_type_imports.py
💤 Files with no reviewable changes: 15
  • tests/assert_helper_allowlists.py
  • src/datamodel_code_generator/model/pydantic_v2/base_model.py
  • src/datamodel_code_generator/model/pydantic_v2/root_model.py
  • src/datamodel_code_generator/model/pydantic_v2/dataclass.py
  • src/datamodel_code_generator/_parse_memo.py
  • tests/parser/test_fact_finality.py
  • tests/data/expected/main/custom_import_cache_alias_invalidation.py
  • tests/parser/test_base.py
  • tests/data/expected/main/custom_import_cache_invalidation.py
  • src/datamodel_code_generator/parser/avro.py
  • src/datamodel_code_generator/parser/_facts.py
  • tests/data/expected/main/custom_import_cache_generic_base.py
  • tests/data/expected/main/custom_import_cache_unique_items.py
  • src/datamodel_code_generator/parser/_pass_decls.py
  • tests/parser/test_generation.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

📝 Walkthrough

The change removes model and field import caches, computes imports on read, and removes parser cache-retention state and cache-clearing passes. clear_imports_cache remains as a deprecated no-op. Parser tests, expected outputs, allowlists, and architecture documentation are updated.

Changes: Import Cache Removal

Layer / File(s) Summary
Model import computation
src/datamodel_code_generator/model/base.py, src/datamodel_code_generator/_parse_memo.py, src/datamodel_code_generator/model/pydantic_v2/*, src/datamodel_code_generator/parser/_facts.py, src/datamodel_code_generator/parser/generation.py, tests/model/test_base.py, tests/parser/test_generation.py, docs/architecture.md, scripts/generation_store_allowlist.toml
Field and model imports are computed on read. clear_imports_cache remains as a deprecated no-op, and render-cache invalidation retains deduplication-memo handling. Tests check import results and model state without relying on private import-cache keys.
Parser transformation updates
src/datamodel_code_generator/parser/_passes/_shared.py, src/datamodel_code_generator/parser/base.py, src/datamodel_code_generator/parser/avro.py, tests/parser/test_base.py, tests/parser/test_fact_finality.py, tests/parser/test_model_construction_capabilities.py, tests/parser/test_python_type_imports.py
Parser transformation helpers and model updates no longer carry cache-retention arguments or clear import caches. Import aliasing and the transformations themselves remain.
Parser pipeline and coverage updates
src/datamodel_code_generator/parser/base.py, src/datamodel_code_generator/parser/_pass_decls.py, tests/main/test_main_general.py, tests/main/test_main_general.refs, tests/parser/test_generation_store_usage.py, tests/assert_helper_allowlists.py, tests/data/expected/main/*, docs/architecture.md, scripts/generation_store_allowlist.toml
Parser cache-retention state and related clearing passes are removed. Tests and expected outputs no longer assert cache-clearing histories, and documentation and allowlists reflect the removed cache entries.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Possibly related issues

  • Issue 5130: The issue asks that custom model field changes during render() affect prepared fields and imports. This change computes imports on each read.
  • Issue 4822: The issue reports a missing Any import after root-model collapse changes a field type. This change computes imports on each read and updates the test coverage for fixed-tuple imports.
Merge Risk: ⚪ Minimal · up to 34e33

No actionable regression was established in the cache-removal changes. The PR is mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: removing import caches and the code that clears them.
Docstring Coverage Passed Docstring coverage is 85.32% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 109 functions across 9 files. (3 skipped: 3…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 85.32% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 109 functions across 9 files. (3 skipped: 3 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 16.61%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

❌ 44 regressed benchmarks
✅ 6 untouched benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_recommend_options_full_kubernetes_style 16.5 s 23.5 s -29.88%
❌ test_perf_inherited_required_fields[required-base-first] 498.9 ms 703.7 ms -29.1%
❌ test_perf_pattern_properties_adapter_reuse 3 ms 4 ms -25.55%
❌ test_perf_false_reference_validation 257.1 ms 325.9 ms -21.09%
❌ test_perf_ordinary_array_constraint_generation 1.8 s 2.2 s -18.17%
❌ test_perf_simple_pydantic_v2_field_construction 9.1 ms 11.1 ms -18.16%
❌ test_perf_target_render[fastapi-large] 4.7 s 5.8 s -18.08%
❌ test_perf_large_models_pydantic_v2_noformat 1.1 s 1.3 s -17.79%
❌ test_perf_large_models_pydantic_v2_builtin 1.1 s 1.3 s -17.76%
❌ test_perf_extreme_large_schema 12.8 s 15.6 s -17.75%
❌ test_perf_large_models_typed_dict[legacy-requiredness] 950.7 ms 1,155.6 ms -17.73%
❌ test_perf_unique_items_runtime_scalar_validation 2.6 ms 3.2 ms -17.69%
❌ test_perf_large_models_pydantic_v2_builtin_double_quotes 1.1 s 1.4 s -17.47%
❌ test_perf_large_models_single_module_stdout 1.2 s 1.5 s -17.42%
❌ test_perf_openapi_large_pydantic_v2_builtin 1.1 s 1.3 s -17.41%
❌ test_perf_inherited_required_fields[partial-base-first] 873.8 ms 1,057.4 ms -17.36%
❌ test_perf_deep_nested 4.7 s 5.7 s -16.76%
❌ test_perf_target_render[fastapi-small] 15.9 ms 19.1 ms -16.49%
❌ test_perf_graphql_style_pydantic_v2 700.4 ms 838.4 ms -16.46%
❌ test_perf_empty_pydantic_v2_field_render_plans 35.3 ms 42.2 ms -16.44%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing rp15b-import-caches (5b4aa96) with main (9cfd68b)

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 Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@koxudaxi
Koudai Aono (koxudaxi) force-pushed the rp15b-import-caches branch 2 times, most recently from 59503f1 to b412bac Compare October 23, 2026 02:20
Base automatically changed from fix-5076-frames to main October 23, 2026 04:16
@koxudaxi
Koudai Aono (koxudaxi) merged commit 63e80b9 into main Oct 23, 2026
131 of 132 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the rp15b-import-caches branch October 23, 2026 05:16
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: Breaking changes detected

Reasoning: The PR mostly removes the internal imports cache. DataModel.imports and field imports are now computed at each read, and DataModel.clear_imports_cache becomes a deprecated no-op that the parser and GenerationStore never call. The legacy fallback that called clear_imports_cache on objects without invalidate_render_caches was removed, and the tests that guaranteed that legacy custom-model hook contract were deleted. This affects Python API users with custom model subclasses or duck-typed models, so it is flagged as an API change. Separately, _enum_narrowed_by_part_consts now takes a const_support flag and skips narrowing for dialects without const (draft-04, OpenAPI 3.0). That changes the generated types for such schemas when allOf mixes an enum ref with a const part, so it is flagged as a code generation change. The remaining changes are left out because they are internal or additive: private pass declarations and memo table entries, can_retain_cache parameters removed from private helpers, a new defaulted unique field on NameRequested, fact-finality check internals, doc wording and test fixtures.

Content for Release Notes

Code Generation Changes

  • Draft-04 and OpenAPI 3.0 schemas no longer narrow enums by const - When an allOf combines an enum $ref with a part that holds only const, the enum is no longer narrowed to the const value for dialects without const support (draft-04, OpenAPI 3.0), because const is an unknown keyword there. The field now keeps the full referenced enum type (for example AB) instead of a type narrowed to the const value, so generated models for these schemas accept every value of the referenced enum (Remove the import caches and their clearing #5174)

API/CLI Changes

  • Deprecated DataModel.clear_imports_cache is no longer called by the parser - DataModel.imports and field imports are now computed at each read with no cache. clear_imports_cache is now a deprecated no-op, marked with typing_extensions.deprecated, that the parser and GenerationStore never call, and invalidate_render_caches no longer calls it. Custom model subclasses that overrode clear_imports_cache to react to model mutations will no longer be notified. The fallback that called clear_imports_cache() on parent or model objects without invalidate_render_caches was removed, so duck-typed external models must now implement invalidate_render_caches. The private cache attributes DataModel._IMPORTS_CACHE_KEY, DataModelFieldBase._field_imports_cache and DataModelFieldBase._FIELD_IMPORTS_CACHE_MAX_SIZE were also removed (Remove the import caches and their clearing #5174)

This analysis was produced by the release draft workflow

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.

1 participant