Skip to content

Conversation

candleindark
Copy link
Member

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 Pydantic BaseSettings documented in pydantic/pydantic-settings#689.

This workaround is necessary at the moment because it allows reconstitution of the Config instance disclosed by the api/info/ endpoint. (The JSON representation of the Config instance at the endpoint is a serialization of the instance using field names instead of aliases. Though it is possible to serialize a Config instance at the endpoint using aliases, but that's not a desirable option since aliases are obscure.)

Copy link

codecov bot commented Sep 22, 2025

Codecov Report

❌ Patch coverage is 98.27586% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.94%. Comparing base (fdddc69) to head (7eafc38).
⚠️ Report is 7 commits behind head on devendorize.

Files with missing lines Patch % Lines
dandischema/conf.py 94.44% 1 Missing ⚠️
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     
Flag Coverage Δ
unittests 97.94% <98.27%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@candleindark candleindark force-pushed the devendorize-init-config-with-field-name branch 3 times, most recently from 30fa65b to 04a0529 Compare September 23, 2025 20:09
@candleindark candleindark force-pushed the devendorize-init-config-with-field-name branch from 04a0529 to 22bf029 Compare September 23, 2025 20:58
@candleindark candleindark force-pushed the devendorize-init-config-with-field-name branch from dcba92c to 14e134b Compare September 24, 2025 05:01
@candleindark candleindark marked this pull request as ready for review September 24, 2025 05:17
Copy link

@Copilot Copilot AI left a 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.

@candleindark candleindark force-pushed the devendorize-init-config-with-field-name branch from 14e134b to 7eafc38 Compare September 24, 2025 05:29
@yarikoptic yarikoptic merged commit 5406628 into devendorize Sep 24, 2025
70 checks passed
@yarikoptic yarikoptic deleted the devendorize-init-config-with-field-name branch September 24, 2025 18:39
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.

2 participants