====== README ======
Django Waffle is (yet another) feature flipper for Django. You can define the conditions for which a flag should be active, and use it in a number of ways.
.. image:: https://github.com/django-waffle/django-waffle/workflows/Python%20package/badge.svg?branch=master :target: https://github.com/django-waffle/django-waffle/actions :alt: Build Status .. image:: https://badge.fury.io/py/django-waffle.svg :target: https://badge.fury.io/py/django-waffle :alt: PyPI status badge
:Code: https://github.com/django-waffle/django-waffle :License: BSD; see LICENSE file :Issues: https://github.com/django-waffle/django-waffle/issues :Documentation: https://waffle.readthedocs.io/
Hello,
We've been using django-waffle quite a lot, and noticed that inherited child classes aren't able to flip the switch state overridden in a given parent class. This behaviour is the case for django's override_settings
and was added around 2013, this means that we often assume django-waffle has the same behaviour. The implementation idea below borrows some similar features.
We've done some work in this commit and will briefly summarise the expected behaviour below:
``` @override_switch('foo', active=False) class ParentTestClass(TestCase): pass
@override_switch('foo', active=True) class ChildTestCase(ParentTestCase):
def test_switch_state(self):
# I expect this to be true
self.assertTrue(waffle.switch_is_active('foo'))
``` What are your thoughts on this addition?
I ran into an error that occured due to a typo in the name of a waffle flag in my code. It would have been much better (IMO), and the bug would have been picked up much earlier, had flag_is_active
failed hard for non-existent flags. Failing silently can be dangerous, and whilst I appreciate I can set WAFFLE_LOG_MISSING_FLAGS
to logging.ERROR
to increase visibility, this will still not cause a request to fail hard. In development environments, I tend not to pay particular attention to logs unless I'm specifically looking for something. However, a hard failure would pick up the typo before it makes its way to production.
Obviously, not everyone would want the behaviour I suggest above (quite apart from the fact that it would be a breaking change). As such, an extra configuration setting such as WAFFLE_RAISE_MISSING_FLAGS
would be needed. There are currently quite a lot of configuration settings for waffle. For each of FLAG
, SWITCH
and SAMPLE
we have:
- WAFFLE_*_DEFAULT
- WAFFLE_CREATE_MISSING_*S
- WAFFLE_LOG_MISSING_*S
With this in mind, we probably do not want an extra configuration setting. There are no doubt other behaviours that other uses would wish for in the case of a missing flag, and it's untenable to provide a new setting for each of them.
Instead of introducing a new config setting, I propose that we replace WAFFLE_CREATE_MISSING_*S
and WAFFLE_LOG_MISSING_*S
with a new setting WAFFLE_HANDLE_MISSING_*S
which would be a string that points to a function that would be called when an entity is missing. For example:
```
WAFFLE_HANDLE_MISSING_FLAGS = "some_file.handle_missing_flags"
def handle_missing_flags(name): # potentially log a message, create a flag and do anything else you want # optionally return a flag ``` (If a flag is returned the flag would be cached, and the value from the flag would be used, otherwise the default value would be used - as is the current behaviour).
This would have several advantages.
- The default function would use the existing WAFFLE_CREATE_MISSING_*S
and WAFFLE_LOG_MISSING_*S
settings so that introducing the setting would result in no change in behaviour.
- We can then utilise the django checks framework to provide warnings that the old settings will eventually be deprecated, and in time update those warnings to errors. Suitable documentation could also be provided to guide migration to the new system (although this should be reasonably straight-forward). This will mean a pleasant deprecation timeline.
- This allows users greater flexibility to provide the individual functionality they want.
- This actually reduces the number of configuration settings whilst protecting against future settings bloat.
(Part of me would like to subsume WAFFLE_*_DEFAULT
into the new setting too, but seeing as the default values are used in WaffleJS this would be difficult.)
If there is support for this proposition I would be more than happy to submit a PR. I look forward to any feedback on the above.
Up until now, the override_flag
test util was only useful to completely activate or deactivate a flag. It didn't allow to provide more customization for all the internal checks it makes, like evaluating if the request user is authenticated or staff.
This change provides that functionality, without breaking the current API, to avoid breaking changes. Now, users can provide more granular arguments to override_flag
, for a more flexible flag testing.
Closes #439.
I am upgrading from django-waffle==0.19.0
to current django-waffle
on Django 3.1.
I am getting the above TypeError which seems to be related to the changes made in #447.
Are there any hints on how to modify existing code the deal with the read_only
change?
The setting WAFFLE_SWITCH_MODEL
allows using a custom switch model. It's documented on the Switches page but not on the Configuring Waffle page. For comparison, the equivalent setting for flags, WAFFLE_FLAG_MODEL
, is documented on both the Flags and Configuring Waffle pages.
Perhaps there are other settings missing from the Configuring Waffle page? I haven't checked.
It would be very useful if testing utils such as override_switch
and override_flag
were available for pytest style classes as class decorators. Is this feature somewhere on the road map?
Full Changelog: https://github.com/django-waffle/django-waffle/compare/v2.7.0...v3.0.0
Full Changelog: https://github.com/django-waffle/django-waffle/compare/v2.6.0...v2.7.0
Full Changelog: https://github.com/django-waffle/django-waffle/compare/v2.5.0...v2.6.0
Full Changelog: https://github.com/django-waffle/django-waffle/compare/v2.4.1...v2.5.0
Reverted: Creating missing flags for all attempts to access the missing flag
feature-flags