Skip to content

fix(di): @bean(primary) for shared return type + @lazy init pipeline (v26.06.32)#59

Merged
ancongui merged 1 commit into
mainfrom
fix/di-bean-primary-and-lazy-lifecycle
Jun 7, 2026
Merged

fix(di): @bean(primary) for shared return type + @lazy init pipeline (v26.06.32)#59
ancongui merged 1 commit into
mainfrom
fix/di-bean-primary-and-lazy-lifecycle

Conversation

@ancongui
Copy link
Copy Markdown
Contributor

@ancongui ancongui commented Jun 7, 2026

Two regressions surfaced by the final Spring-parity audit (both in features shipped this session):

  1. @bean(primary=True) ignored across multiple @bean of one return type — the single-bean direct return-type registration kept the first-processed impl; a later @bean(primary=True) now overwrites it so ctx.get_bean(Interface) returns the primary. (Class-level @primary was already correct; the Protocol-return test passed but an ABC/concrete interface failed — now both covered.)
  2. @lazy beans skipped the init pipeline — a lazily-created singleton got ctor + field injection only, never @post_construct / BeanPostProcessors / AOP weaving (verified: aspects didn't fire on lazy beans). The container now runs a post-create hook (installed by ApplicationContext after startup) over lazily-created singletons. Async @post_construct on a lazy bean is unsupported in the sync path and warns.

Tests

tests/container/test_di_audit_regressions.py (3): @bean(primary) wins for a shared ABC return type; @lazy runs @post_construct; @lazy runs BeanPostProcessors (the AOP-weaving path).

Gates

mypy --strict (614) ✓ · ruff + ruff format ✓ · full suite 3790 passed.

Wave A of the audit fixes. Next: FastAPI serialization wiring, @transactional CancelledError commit + read_only, Kafka per-message isolation.

… full init pipeline + bump v26.06.32

Two regressions found by the final parity audit:
- @bean(primary=True): the direct return-type registration was created only for the first
  @bean method and never updated, so resolve(Interface) returned a non-primary impl. A later
  @bean(primary=True) for the same return type now overwrites the direct registration.
- @lazy beans skipped @post_construct + BeanPostProcessors + AOP weaving (built post-startup
  via _create_instance, never run through the init passes). The container now calls a
  post-create hook (installed by ApplicationContext after startup) that runs BeanPostProcessors
  + @post_construct on lazily-created singletons; async @post_construct on lazy beans warns.

Tests: tests/container/test_di_audit_regressions.py (3). Gates: mypy --strict (614),
ruff + format, full suite 3790 passed.
@ancongui ancongui merged commit e468099 into main Jun 7, 2026
5 checks passed
@ancongui ancongui deleted the fix/di-bean-primary-and-lazy-lifecycle branch June 7, 2026 10:19
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