Skip to content

Env.__contains__ ignores configured prefix #644

Description

@paduszyk

When a prefix is set, Env.get_value uses the prefixed name, but Env.__contains__ still checks only the raw key.

Current behavior

def __contains__(self, var: _str):
    return var in self.ENVIRON

Repro

import environ

env = environ.Env()
env.prefix = "DJANGO_"
env.ENVIRON["DJANGO_DEBUG"] = "1"

env.get_value("DEBUG")  # returns "1"
"DEBUG" in env          # returns False

Expected

"DEBUG" in env should return True in this case, consistent with get_value (or simple call).

Suggested fix

def __contains__(self, var: _str):
    return f"{self.prefix}{var}" in self.ENVIRON

Happy to open a PR with this change and a test covering prefixed membership.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions