Skip to content

fix: isolate model imports from dependency runtime - #412

Open
marlon-costa-dc wants to merge 6 commits into
0.12.0-devfrom
fix/model-import-runtime-isolation-20260828
Open

fix: isolate model imports from dependency runtime#412
marlon-costa-dc wants to merge 6 commits into
0.12.0-devfrom
fix/model-import-runtime-isolation-20260828

Conversation

@marlon-costa-dc

@marlon-costa-dc marlon-costa-dc commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Root cause\n\nImporting the public model facade traversed collection metadata normalization through the composite runtime facade. That initialized dependency-injector wiring and FastAPI/OpenAPI during test collection. Under host commit pressure, Pydantic schema construction then failed with MemoryError before tests could run.\n\n## Change\n\n- make the internal runtime package exports lazy\n- route collection metadata normalization to its leaf owner\n- prove that resolving flext_core.m.StrictModel loads neither dependency_injector nor fastapi\n\n## Evidence so far\n\n- RED: make test WHAT=all FILE=tests/unit/test_lazy_exports.py — new regression failed and listed the unintended modules\n- GREEN: same command — 1 passed, 23 deselected\n- make fmt — 524 files already formatted\n\nWIP: consumer and full native gates still running.


Summary by cubic

Isolates model imports from the dependency runtime and types the facade's field/private-attr helpers so test collection no longer initializes dependency_injector or FastAPI/OpenAPI (which failed with MemoryError under memory pressure) and PrivateAttr supports default, default_factory, and per-instance state.

  • Makes the internal runtime package exports lazy.
  • Routes collection metadata normalization to the leaf _runtime._metadata owner instead of the composite runtime facade.
  • Types facade-exported PrivateAttr and reuses it in the utilities facade so both m.PrivateAttr and u.PrivateAttr support default, default_factory, and per-instance state.
  • Types immutable mapping defaults so generated schemas retain concrete value types.
  • Replaces lambdas with functools.partial and typed callback helpers in handlers, config, and mapper to keep type contracts explicit.
  • Adds regression tests for the lazy import path and private-attr instance semantics.

Written for commit 187453f. Summary will update on new commits.

Review in cubic

@marlon-costa-dc

Copy link
Copy Markdown
Contributor Author

Root-cause evidence: the new public regression first failed by listing dependency_injector plus 38 FastAPI/OpenAPI modules after resolving flext_core.m.StrictModel, then passed after the owner fix. The original flext-infra consumer also completed 21/21 in tests/unit/codegen/test_codegen_ci_matrix.py without MemoryError. Operator approval was provided in the active rollout session; full remote gates remain required.

@marlon-costa-dc
marlon-costa-dc marked this pull request as ready for review August 28, 2026 17:09
Comment thread src/flext_core/_models/pydantic.py Fixed
Comment thread src/flext_core/_models/pydantic.py Fixed
Comment thread src/flext_core/_models/pydantic.py Fixed
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant