Repository navigation
feat: provide settings through the container and derive engine URLs - #81
Merged
Merged
Conversation
Engines take Settings from ioc.Config.settings and get their URL via provider.derive, so tests override settings instead of monkeypatching the module-level instance. Requires modern-di 4.3.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Settings used to reach the engines through the module-level
settingsinstance, so tests changed engine config withmonkeypatch.setattr(settings, ...). This PR provides settings through the container and usesprovider.derive(modern-di 4.3.0) for the engine URLs. It is the setup asked about in modern-python/.github#136.Changes
ioc.Config.settingsis a cachedFactory(Settings).create_sa_engine(*, settings, url, read_only=False)no longer reads the global. Both engines take the whole settings object. The primary engine gets its URL fromConfig.settings.derive(lambda s: s.db_dsn_parsed), and the read engine fromConfig.settings.derive(read_engine_url), which holds the replica fallback.create_primary_sa_engineandcreate_read_sa_engineare removed.Config.settingson a fresh container and check the read engine's URL.test_poolpasses an explicitSettings(...)instead of monkeypatching.modern-di>=4.3.0,<5is a direct dependency, and the lock moves modern-di from 4.0.0 to 4.3.0.Design notes
deriveis used only for the value that differs between the two engines.settingsstays forapp/__main__.py,migrations/env.pyandbuild_app, which run outside the container or before it exists.test_mainkeeps its monkeypatch. The container builds its ownSettingsfrom the same environment.Config.settingsonly affects engines built after it.Testing
just test: 87 passed, 100% coverage.just lintis clean.