Skip to content

[bug] filter_strategy config not working #760

@rdettai

Description

@rdettai

Describe the bug
It seems that the filter_strategy config (which by the way is misspelled int the docs) is not taken into account when used in the Dynaconf constructor.

To Reproduce
Steps to reproduce the behavior:

  1. Having the following folder structure
    Just a plain python script.

  2. Having the following config files:
    No config file, just using env variables

  3. Having the following app code:

Code

/test/test.py

import dynaconf

class CustomFilter:
    def __call__(self, data):
        print("this is never called")
        return {
            k: v
            for k, v in data.items()
            if k.startswith("PREFIX")
        }


if __name__ == "__main__":
    dc = dynaconf.Dynaconf(
        envvar_prefix=False,
        filter_strategy=CustomFilter(),
    )
    print(dc.as_dict())
  1. Executing under the following environment
Execution
PREFIX_VAR="HELLO" OTHER_VAR="WORLD" python test.py

Expected behavior
CustomFilter should be called ("this is never called" should be displayed) and only the PREFIX_VAR should be in dict, not OTHER_VAR

Environment (please complete the following information):

  • OS: Linux version 5.10.60.1-microsoft-standard-WSL2
  • Dynaconf Version 3.1.9
  • Framework: None

Context

I was looking for a way to filter out empty environment variables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions