Skip to content

SsmBaseSettings is always case-sensitive #16

@keith-at-coastal

Description

@keith-at-coastal

There appears to be a bug that prevents reading case-insensitive settings from the environment or a .env file. Here is a minimal example of the issue:

from pydantic_ssm_settings import SsmBaseSettings
from pydantic import ValidationError
from os import environ


class SimpleSettings(SsmBaseSettings):
    foo: str


# can read parameters from the environment if the case matches
environ['foo'] = 'foo'
s = SimpleSettings()
assert s.foo == 'foo'
print('Loaded just fine, as expected')
del environ['foo']

# can't read parameters from the environment if the case does not match
environ['FOO'] = 'foo'
try: 
    s = SimpleSettings()
except ValidationError:
    print('Failed to load with upper case variable names')
del environ['FOO']

# can't explicitly set the case sensitivity 
environ['FOO'] = 'foo'
try:
    s = SimpleSettings(_case_sensitive=False)
except TypeError as err:
    assert "multiple values for argument '_case_sensitive'" in str(err)
    print('Failed to force case insensitive') 

I tracked the problem down to an incorrect call to super().__init__():

super().__init__(self, *args, **kwargs)

The current call is super().__inti__(self, *args, **kwargs), but is should not include self. The result of this bug is that self gets passed along as the _case_sensitive argument. It is "truthy" so we end up with a case sensitive settings class, and because it is already provided, we cannot override it.

I think the fix is as simple as deleting the offending self.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions