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

Option for flags to work even without request object #129

Open
mwaaas opened this issue Aug 27, 2024 · 1 comment
Open

Option for flags to work even without request object #129

mwaaas opened this issue Aug 27, 2024 · 1 comment

Comments

@mwaaas
Copy link

mwaaas commented Aug 27, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@mwaaas and others