Skip to content
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

Should strip whitespace #13

Closed
FichteFoll opened this issue Sep 3, 2024 · 5 comments · Fixed by #16
Closed

Should strip whitespace #13

FichteFoll opened this issue Sep 3, 2024 · 5 comments · Fixed by #16
Assignees
Labels
bug Something isn't working

Comments

@FichteFoll
Copy link

The default implementation of SecretsSettingsSource strips the read file contents of any whitespace but this one here does not.

Setting str_strip_whitespace in the model_config does not seem to have any effect on this either.

@makukha
Copy link
Owner

makukha commented Sep 3, 2024

Thank you! This is definitely a bug.

@makukha makukha added the bug Something isn't working label Sep 3, 2024
@makukha makukha self-assigned this Sep 3, 2024
@makukha
Copy link
Owner

makukha commented Sep 3, 2024

Btw, I just checked that str_strip_whitespace is not respected by original SecretsSettingsSource:

def test_str_strip_whitespace_not_respected(secrets_dir):
    class Settings(BaseSettings):
        key: str

        model_config = SettingsConfigDict(
            secrets_dir=secrets_dir,
            str_strip_whitespace=False,
        )

    secrets_dir.add_files(
        ('key', ' value '),
    )

    conf = Settings()
    assert conf.key == 'value'  # str_strip_whitespace not respected

@makukha makukha linked a pull request Sep 3, 2024 that will close this issue
@makukha
Copy link
Owner

makukha commented Sep 3, 2024

@FichteFoll thank you for the bug report. The fix was trivial and already merged to main branch. I will update PyPI release as soon as all bugs reported will be fixed (a couple of days at most).

Thank you for your interest in the package!

@FichteFoll
Copy link
Author

FichteFoll commented Sep 3, 2024

Btw, I just checked that str_strip_whitespace is not respected by original SecretsSettingsSource:

Indeed, it was simply always stripped. Perhaps this is an upstream bug.

I simply monkey-patched FileSecretsSettingsSource.load_secrets while waiting for a patch but will gladly remove it once the new version is out.

Thanks for adapting this into a package until this feature hopefully lands in the mainline pydantic-settings project.

@makukha
Copy link
Owner

makukha commented Sep 3, 2024

I simply monkey-patched FileSecretsSettingsSource.load_secrets while waiting for a patch but will gladly remove it once the new version is out.

The new version 0.3.0 with all your suggestions and bug reports fixed is released on PyPI.
Thank you for the feedback!

Thanks for adapting this into a package until this feature hopefully lands in the mainline pydantic-settings project.

There's already a PR to pydantic_settings for multiple secrets_dir waiting to be merged. And yes, the plan is to update pydantic_settings with at least some of features from this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants