Skip to content

fix(container): union-safe bean-name derivation (v26.06.95)#124

Merged
ancongui merged 1 commit into
mainfrom
fix/union-safe-bean-name
Jun 10, 2026
Merged

fix(container): union-safe bean-name derivation (v26.06.95)#124
ancongui merged 1 commit into
mainfrom
fix/union-safe-bean-name

Conversation

@ancongui

Copy link
Copy Markdown
Contributor

Summary

Registering a bean whose implementation type is a PEP 604 union (X | Y, a types.UnionType) crashed application startup:

AttributeError: 'types.UnionType' object has no attribute '__name__'
  bean_name = rep.name or rep.impl_type.__name__

surfaced as a BeanCreationException from ApplicationContext.start() — any app with a union-typed bean failed to boot.

Fix

  • New union-safe Registration.display_name property: explicit name → else impl_type.__name__ → else the union member names → str(). Never raises.
  • Used for default bean-name derivation (application_context.py) and scope-resolution error messages (container.py).
  • Regression tests in tests/container/test_registration_display_name.py.

Release

  • Version 26.6.9426.6.95; CHANGELOG.md + README version badge updated.
  • Tag v26.06.95 pushed.

Verification

  • tests/container + tests/context340 passed; new regression tests 4 passed.
  • Verified live: a downstream service with a union-typed bean now starts clean on v26.06.95 (was crashing on v26.06.94).

PEP 604 union impl types (X | Y) are types.UnionType and lack __name__, so default
bean-name derivation ('rep.name or rep.impl_type.__name__') raised AttributeError
during ApplicationContext.start() (surfaced as BeanCreationException), breaking
startup for any app with a union-typed bean.

Add a union-safe Registration.display_name (falls back to union member names then
str()) and use it for bean-name derivation + scope-resolution error messages. Adds
regression tests; bumps 26.6.94 -> 26.6.95; updates CHANGELOG + README badge.
@ancongui ancongui merged commit 920ffaa into main Jun 10, 2026
5 of 7 checks passed
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