Skip to content

Option for flags to work even without request object #129

@mwaaas

Description

@mwaaas

I have created a custom condition that doesn't require request object and works fine.

But issue is a runtime error occurs when by mistake a user adds a flag with a condition that requires requests, making my code to fail at runtime with request is not required.

For instance using flags in celery tasks.

At the moment am doing this hack

``
from flags import conditions
def patched_check(self, **kwargs):
if self.fn is not None:
try:
return self.fn(self.value, **kwargs)
except Exception as e:
logger.exception(f"Error checking condition {self.condition}: {e}")
return False
return False

Apply the monkey patch

Condition.check = patched_check
``

Is this something that should be contributed back to support exceptions and just return false

i.e

flag_enabled("feature_flag", handle_exception=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions