Skip to content

Defer model build#447

Open
DamianCzajkowski wants to merge 10 commits into
mainfrom
AR-5/defer-model-build
Open

Defer model build#447
DamianCzajkowski wants to merge 10 commits into
mainfrom
AR-5/defer-model-build

Conversation

@DamianCzajkowski

Copy link
Copy Markdown
Collaborator

Adds an opt-in defer_model_build setting (default false) that makes importing
a generated package much faster for large schemas, plus the build/tooling and
correctness fixes the change that rests on.

What it adds

defer_model_build setting when enabled:

  • sets defer_build=True on the generated BaseModel, so each model's core
    The schema is built on first use instead of at import time;
  • drops the eager Model.model_rebuild() calls from the generated modules.

For a large schema, this cuts import time roughly in half, since importing the
package no longer builds every Pydantic model up front. It's fully opt-in and
changes no generated code until you set it. Requires pydantic >= 2.9 in the
environment that runs the generated package (defer_build is not a ConfigDict
key before 2.5).

[tool.ariadne-codegen]
defer_model_build = true

…core lock

- add hatch check-code/check-fmt/check-types static-analysis envs pinned to the
  project ruff, replacing the deprecated `hatch fmt`
- register the `performance` marker and deselect it by default (timing guards
  are too noisy for shared CI; run with `hatch test -- -m performance`)
- refresh uv.lock to graphql-core 3.2.11, matching the committed schema fixtures
`_copy_files` keyed the base-model rewrite off `source_path.name ==
"base_model.py"`, but with `multipart_uploads = false` the base model is
copied from `base_model_no_upload.py`. The check was therefore false, so
`defer_model_build` (and `ignore_extra_fields = false`) were silently dropped
from the generated `BaseModel` while the settings summary still reported them
as enabled. Key the rewrite off the base-model source path instead, so it fires
in both upload modes.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto 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

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 03674966-1076-470e-a8b6-f5f9cac06f65

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch AR-5/defer-model-build

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.

Comment thread ariadne_codegen/client_generators/package.py Outdated
Comment thread tests/performance/test_codegen_performance.py Outdated
Comment thread tests/performance/test_codegen_performance.py Outdated
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