Accept DatabaseConfig values by field name, not only by env alias - #37
Merged
Conversation
Its aliased fields carry a validation_alias, and a pydantic v2 model
accepts an aliased field only by that alias unless it opts into
populate_by_name. AuthConfig does; DatabaseConfig did not. So every value
passed by field name was silently discarded:
DatabaseConfig(dynamodb_table_name="t").dynamodb_table_name -> None
DatabaseConfig(**{"JVSPATIAL_DYNAMODB_TABLE_NAME": "t"}) -> "t"
Two paths were affected. server_config_overrides_from_env() keys its
database group by field name, so its dynamodb and postgres mappings never
reached the model. And embedding hosts that build a DatabaseConfig
directly -- jvagent passes dynamodb_table_name / dynamodb_region this way
-- were likewise ignored, which means an app.yaml table name or region has
never taken effect for DynamoDB.
Nothing raised, because the adapters read the same settings from env
themselves and carried on. The configuration object simply was not the
source of truth it appeared to be. DynamoDB has been affected since those
fields were added; postgres inherited it in 0.0.16.
Fix is the one line AuthConfig already carries. Tests cover both
population paths for all aliased fields and drive
server_config_overrides_from_env output onto the model -- the path that
was inert, and that my earlier postgres tests missed by asserting the
dict rather than the model built from it.
Benchmark comparisonThreshold: ±25% (informational, does not block merge)
|
This was referenced Aug 5, 2026
Open
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.
Type of Change
Summary
What does this PR address?
DatabaseConfigsilently discarded every value passed by field name:Its aliased fields carry a
validation_alias, and a pydantic v2 model accepts an aliased field only by that alias unless it opts intopopulate_by_name.AuthConfigopts in (config_groups.py:138);DatabaseConfignever did.Description
Bug Fixes:
The bug. Two paths pass these fields by name, and both were inert:
server_config_overrides_from_env()builds its database group keyed by field name (db["dynamodb_table_name"] = ..., and since 0.0.16db["postgres_dsn"] = ...). None of it reached the model.DatabaseConfigdirectly. jvagent passesdynamodb_table_name/dynamodb_region/dynamodb_endpoint_urlthis way — so anapp.yamltable name or region has never actually taken effect for DynamoDB.Why it went unnoticed. Nothing raised. The adapters read the same settings from env themselves, so deployments configured purely through env vars worked exactly as expected — the configuration object just wasn't the source of truth it appeared to be. It only becomes visible when someone configures via
app.yaml, or asserts on the model.Scope. DynamoDB has been affected since those fields were added. Postgres inherited it in 0.0.16.
The fix. The single line
AuthConfigalready carries:Alias population is unchanged — both spellings now work, which is what the env-override path needs.
Changes Made
jvspatial/api/config_groups.py—populate_by_nameonDatabaseConfig, with a comment explaining why the aliased fields need it.tests/api/test_database_config_population.py— new. Both population paths for all 9 aliased fields (dynamodb + postgres), integer fields, unaliased fields unaffected, and one test drivingserver_config_overrides_from_env()output onto the model — the path that was inert.CHANGELOG.md— entry under[Unreleased].Checklist
DatabaseConfig(...)returningNonefor every aliased field).test_server_config,test_database_configurator,test_env_adapter_postgres,test_server_env_integration, plus the new file) all green. Full-suite run was still going when this was opened; CI is authoritative and re-runs it.Steps to Test
Against
mainthese fail withassert None == 'my-table'for each aliased field. The end-to-end shape:Additional Context
Found while wiring jvagent's Postgres settings through
ServerConfig— the passthrough was written correctly and did nothing, which is what led back here.This also exposes a gap in my own #35 tests.
test_postgres_env_maps_into_database_groupasserts the dictserver_config_overrides_from_env()produces, never that the dict lands on the model. It passed happily while the path was dead. The newtest_env_adapter_output_lands_on_the_modelcloses that.Worth considering as a follow-up: the same
validation_alias-without-populate_by_nameshape would be an easy trap in any future config group. A test that walks every group inconfig_groups.py, finds fields with avalidation_alias, and asserts field-name population would prevent a repeat — happy to add it here or separately.Questions or Concerns
None on the fix itself. One judgment call worth confirming: this makes
app.yaml-supplied DynamoDB settings actually take effect for the first time. For a deployment that has both anapp.yamltable name and aJVSPATIAL_DYNAMODB_TABLE_NAMEenv var pointing at different tables, behavior changes — env previously won by default. That's the documented precedence restored, but if you'd rather it ship in a minor rather than a patch, say so.