django-flags icon indicating copy to clipboard operation
django-flags copied to clipboard

Ability to override via query parameter and persist for session?

Open truthdoug opened this issue 4 months ago • 0 comments

A pattern we've used (with internal code, not django-flags):

  • have a site-wide feature flag, either in django settings or (more commonly) in django-constance
  • middleware or hook that detects query parameters that explicitly choose one state or the other. For example, if the feature is called newfeature then ?newfeature would always enable it and ?no-newfeature would disable it
  • the middleware also stores the overriden value in the django user session

With this the priority of choosing the feature or not is:

  1. query parameter - if it exists on the current request, that trumps all (and is set on the session)
  2. django session value - if the feature is explicitly set or unset in the session, use that
  3. global value - otherwise use the site-wide setting

I'm newly finding out about django-flags and I've read through examples in the documentation but don't readily see a way to implement this overriding behavior. Is there a way to do this? Perhaps with a combination of conditions for the feature?

truthdoug avatar Oct 11 '24 15:10 truthdoug