Skip to content

fix: allow concrete and ForwardRef relations on one model - #1931

Open
collerek wants to merge 1 commit into
masterfrom
fix/forward-ref-reverse-rebuild
Open

collerek wants to merge 1 commit into
masterfrom
fix/forward-ref-reverse-rebuild

Conversation

@collerek

@collerek collerek commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

A model declaring a concrete relation next to a ForwardRef one (e.g. ForeignKey(Author) and ForeignKey(ForwardRef("Book"))) failed at class creation with PydanticUndefinedAnnotation: the reverse field on Author embeds a copy of the model whose Book ref is still unresolved. Schema rebuilds triggered while refs are pending now defer instead of raising, and update_forward_refs() rebuilds the related and through models left incomplete. An undefined ref still raises NameError from update_forward_refs().

A model declaring a concrete relation next to a ForwardRef relation failed
at class creation with PydanticUndefinedAnnotation: the reverse field on the
concrete target embeds a copy of the model whose forward ref is unresolved.
Schema rebuilds now defer instead of raising, and update_forward_refs()
rebuilds the related and through models left incomplete.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Nov 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 18.9%

2 warnings

⚠️ 112 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 3 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 123 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_get_documents_page_with_json[250] 15.9 ms 35.4 ms -55.07%
❌ test_get_one_wide_model[250] 10 ms 11.1 ms -10.18%
⚡ test_get_one_wide_model[500] 8.4 ms 6.4 ms +32.16%

Tip

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


Comparing fix/forward-ref-reverse-rebuild (7ecfe7d) with master (5ff3dff)

Open in CodSpeed

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants