Skip to content

fix: read instance attributes in api_bootstrapper_config#32

Merged
lesnik512 merged 1 commit into
mainfrom
fix/settings-self-reference
Jun 26, 2026
Merged

fix: read instance attributes in api_bootstrapper_config#32
lesnik512 merged 1 commit into
mainfrom
fix/settings-self-reference

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Bug

Settings.api_bootstrapper_config built its LitestarConfig from the module-global settings singleton instead of self:

@property
def api_bootstrapper_config(self) -> LitestarConfig:
    return LitestarConfig(
        service_name=settings.service_name,   # ← global, not self
        ...
    )

So any Settings instance other than the singleton — or any access during the singleton's own construction — silently produced the singleton's values rather than its own.

Fix

Every field now reads self.*.

Test (TDD — failing first)

Added tests/test_settings.py, which constructs a Settings(service_name="custom-service", service_version="9.9.9") and asserts api_bootstrapper_config reflects the instance.

  • Before the fix (RED): assert 'Litestar template' == 'custom-service' — fails, proving the global leak.
  • After the fix (GREEN): passes.

20 passed, 100% coverage.

🤖 Generated with Claude Code

The api_bootstrapper_config property built its LitestarConfig from the
module-global settings singleton instead of self, so any Settings
instance other than the singleton (or any access before the singleton
is constructed) silently produced the singleton's values.

Switch every field to self.*. Add a regression test that constructs a
Settings with non-default service_name/service_version and asserts the
config reflects the instance, not the global.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 52f0256 into main Jun 26, 2026
2 checks passed
@lesnik512 lesnik512 deleted the fix/settings-self-reference branch June 26, 2026 17:49
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