-
Notifications
You must be signed in to change notification settings - Fork 14
Workaround to allow dandischema.conf.Config
to be initialized with field names
#336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Workaround to allow dandischema.conf.Config
to be initialized with field names
#336
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devendorize pydantic/pydantic#336 +/- ##
===============================================
- Coverage 97.94% 97.94% -0.01%
===============================================
Files 18 18
Lines 2292 2340 +48
===============================================
+ Hits 2245 2292 +47
- Misses 47 48 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
30fa65b
to
04a0529
Compare
04a0529
to
22bf029
Compare
dcba92c
to
14e134b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a workaround to allow dandischema.conf.Config
to be initialized with field names instead of field aliases, circumventing a Pydantic BaseSettings bug. This enables proper reconstitution of Config instances from JSON serialization using field names rather than obscure aliases.
- Adds a custom
settings_customise_sources
method that wraps the init settings source to convert field names to aliases - Updates all test cases to use field names instead of aliases when creating Config instances
- Adds new tests for initialization with both field names and aliases, dotenv file handling, and round-trip serialization
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
dandischema/conf.py | Implements the workaround by adding a custom settings source that maps field names to aliases for initialization |
dandischema/tests/test_conf.py | Updates test cases to use field names and adds comprehensive tests for the new initialization behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
14e134b
to
7eafc38
Compare
This PR implements a workaround to allow
dandischema.conf.Config
to be initialized with the names of the fields in the model instead of the aliases of the fields. I.e., it circumvents the bug in PydanticBaseSettings
documented in pydantic/pydantic-settings#689.This workaround is necessary at the moment because it allows reconstitution of the
Config
instance disclosed by theapi/info/
endpoint. (The JSON representation of theConfig
instance at the endpoint is a serialization of the instance using field names instead of aliases. Though it is possible to serialize aConfig
instance at the endpoint using aliases, but that's not a desirable option since aliases are obscure.)