fix: coerce env var strings to schema-declared boolean/integer types#482
Open
gaoflow wants to merge 1 commit into
Open
fix: coerce env var strings to schema-declared boolean/integer types#482gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
Environment variables are always strings, but providers declare schema
properties with type "boolean" or "integer". Reading these settings via
NOTIFIERS_<PROVIDER>_<ARG> raised BadArguments ("'true' is not of type
'boolean'") because the raw string was passed straight to jsonschema.
Add `_coerce_environs()` to `SchemaResource`, called by `_get_environs()`,
which inspects the provider's JSON schema for each returned key and casts:
- "boolean" → uses the existing `text_to_bool()` helper ("true"/"1"/"yes" → True)
- "integer" → int()
- "number" → float()
- everything else → unchanged string
Fixes liiight#387.
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.
Problem
Environment variables are always strings, but provider schemas declare fields with
"type": "boolean"or"type": "integer". When these settings are supplied through environment variables (e.g.NOTIFIERS_EMAIL_TLS=true), they are passed as raw strings to jsonschema validation, which raisesBadArguments:This has been reported in issue #387 (open since 2020).
Fix
Add
_coerce_environs()toSchemaResource, called at the end of_get_environs(). It inspects each returned key against the provider's JSON schema and casts:"boolean"→ uses the existingtext_to_bool()helper ("true"/"1"/"yes"/"on"→True, etc.)"integer"→int()"number"→float()The fix is ~30 lines, all pure Python, and places the responsibility where the schema context is already available.
Before / After
Tests
A new
test_environ_bool_and_int_coerciontest intests/test_core.pycovers"true"→True,"false"→False, and"587"→587. All 34 tests pass.This pull request was prepared with the assistance of AI, under my direction and review.