A feature flipper for Django

django-waffle, updated 🕥 2022-12-02 00:48:17

====== 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/

Issues

override_switch in inherited classes should take precedence

opened on 2023-02-15 12:26:36 by oliveryh

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?

Consolidate config settings for handling missing entities

opened on 2022-12-27 22:56:36 by tim-mccurrach

The problem

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.

Is this configuration bloat??

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.

A proposed solution

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: ```

settings.py

WAFFLE_HANDLE_MISSING_FLAGS = "some_file.handle_missing_flags"

some_file.py

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.

feat: Allow override_flag testutil to set different checks

opened on 2022-12-02 00:48:16 by adamantike

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.

TypeError: is_active() got an unexpected keyword argument 'read_only'

opened on 2022-10-01 17:01:55 by cclauss

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?

`WAFFLE_SWITCH_MODEL` is missing from the "Configuring Waffle" docs page

opened on 2022-08-16 09:44:17 by allanlewis

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.

Enable pytest support for django waffle

opened on 2022-08-02 14:50:10 by rievva-aleksandra

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?

Releases

v3.0.0 2022-08-30 17:19:10

What's Changed

  • Update Github actions by @ulgens in https://github.com/django-waffle/django-waffle/pull/459
  • Pluggable Switch and Sample models #456 by @cole-jacobs in https://github.com/django-waffle/django-waffle/pull/457
  • Remove support for EOL Python versions by @ulgens in https://github.com/django-waffle/django-waffle/pull/460
  • Update Django versions by @ulgens in https://github.com/django-waffle/django-waffle/pull/461

New Contributors

  • @ulgens made their first contribution in https://github.com/django-waffle/django-waffle/pull/459
  • @cole-jacobs made their first contribution in https://github.com/django-waffle/django-waffle/pull/457

Full Changelog: https://github.com/django-waffle/django-waffle/compare/v2.7.0...v3.0.0

v2.7.0 2022-08-22 05:05:41

What's Changed

  • Expose JSON endpoint for Waffle flag/switch/sample state by @shaungallagher in https://github.com/django-waffle/django-waffle/pull/452

Full Changelog: https://github.com/django-waffle/django-waffle/compare/v2.6.0...v2.7.0

v2.6.0 2022-07-20 05:28:40

What's Changed

  • Fixed Django 4.0 compatibility by @triopter in https://github.com/django-waffle/django-waffle/pull/446
  • Added support for custom Sample and Switch models by @shaungallagher in https://github.com/django-waffle/django-waffle/pull/448
  • Added ability to determine if flag is active without persisting new state by @triopter in https://github.com/django-waffle/django-waffle/pull/447
  • Added support for Python 3.10 by @clintonb in https://github.com/django-waffle/django-waffle/pull/450

New Contributors

  • @triopter made their first contribution in https://github.com/django-waffle/django-waffle/pull/446
  • @shaungallagher made their first contribution in https://github.com/django-waffle/django-waffle/pull/448

Full Changelog: https://github.com/django-waffle/django-waffle/compare/v2.5.0...v2.6.0

v2.5.0 2022-06-05 16:45:38

What's Changed

  • fix wording error by @simonkern in https://github.com/django-waffle/django-waffle/pull/440
  • Add config to support disabling admin pages by default. by @onurhunce-planetly in https://github.com/django-waffle/django-waffle/pull/444

New Contributors

  • @onurhunce-planetly made their first contribution in https://github.com/django-waffle/django-waffle/pull/444

Full Changelog: https://github.com/django-waffle/django-waffle/compare/v2.4.1...v2.5.0

v2.4.1 2022-03-28 23:19:45

Reverted: Creating missing flags for all attempts to access the missing flag

v2.4.0 2022-03-28 17:30:58

  • Preventing exceptions for template use cases where a request is not available
  • Creating missing flags for all attempts to access the missing flag
  • Added Italian translations
  • Removed universal wheel

feature-flags