cfpb / django-flags

Feature flags for Django projects
https://cfpb.github.io/django-flags/
Creative Commons Zero v1.0 Universal
260 stars 32 forks source link

Option for flags to work even without request object #129

Open mwaaas opened 3 months ago

mwaaas commented 3 months ago

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)