Skip to content

Commit

Permalink
Remove deprecated waffle API
Browse files Browse the repository at this point in the history
- Remove `edx_toggles.toggles.__future__` module
- Remove call to monitoring for legacy features
- Deprecate WaffleFlagNamespace.set_monitor_value method
- Deprecate LegacyWaffleFlagNamespace._set_monitor_value method

This bumps the version to v4.0.0.
  • Loading branch information
regisb committed Feb 9, 2021
1 parent 61c3a1a commit 6e90bd2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 211 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ Change Log
Unreleased
~~~~~~~~~~

[4.0.0] - 2021-01-24
~~~~~~~~~~~~~~~~~~~~

* BREAKING CHANGE: Remove now unnecessary ``edx_toggles.toggles.__future__`` module.
* BREAKING CHANGE: Remove the following methods and properties: ``LegacyWaffleFlagNamespace.set_monitor_value``, ``LegacyWaffleSwitch.switch_name``, ``LegacyWaffleSwitch.namespaced_switch_name``, ``LegacyWaffleFlag.flag_name``, ``LegacyWaffleFlag.namespaced_flag_name``, ``LegacyWaffleFlag.waffle_namespace``.
* BREAKING CHANGE: Remove ``LegacyWaffleFlagNamespace._set_monitor_value`` method
* Monitoring:

* Add the following custom attribute: "deprecated_legacy_waffle_class"
* Remove the following custom attributes: "deprecated_module_not_supplied", "warn_flag_no_request_return_value", "deprecated_waffle_method", "deprecated_waffle_legacy_method", "deprecated_compatible_legacy_waffle_class".
* Rename ``toggles.internal.legacy.Waffle*`` classes to ``toggles.internal.legacy.LegacyWaffle*``.

[3.1.0] - 2021-01-18
~~~~~~~~~~~~~~~~~~~~

* Dropped support for ``Python3.5``.
* Fix ``toggle_type`` column value from the toggle state report for the ``SettingToggle`` and ``SettingDictToggle`` classes: the column is now set to "django_settings".


[2.1.0] - 2021-01-12
~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion edx_toggles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Library and utilities for feature toggles.
"""

__version__ = '3.1.0'
__version__ = '4.0.0'

default_app_config = 'edx_toggles.apps.TogglesConfig' # pylint: disable=invalid-name
41 changes: 13 additions & 28 deletions edx_toggles/tests/test_legacy_waffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,28 @@
from django.test import TestCase

from edx_toggles.toggles.internal.waffle.legacy import (
WaffleFlag,
WaffleFlagNamespace,
WaffleSwitch,
WaffleSwitchNamespace
LegacyWaffleFlag,
LegacyWaffleFlagNamespace,
LegacyWaffleSwitch,
LegacyWaffleSwitchNamespace
)


class TestWaffleSwitch(TestCase):
class TestLegacyWaffleSwitch(TestCase):
"""
Tests the WaffleSwitch.
Tests the LegacyWaffleSwitch.
"""

def test_namespaced_switch_name(self):
"""
Verify namespaced_switch_name returns the correct namespace switch name
"""
namespace = WaffleSwitchNamespace("test_namespace")
switch = WaffleSwitch(namespace, "test_switch_name", __name__)
self.assertEqual(
"test_namespace.test_switch_name", switch.namespaced_switch_name
)

def test_default_value(self):
namespace = WaffleSwitchNamespace("test_namespace")
switch = WaffleSwitch(namespace, "test_switch_name", module_name="module1")
namespace = LegacyWaffleSwitchNamespace("test_namespace")
switch = LegacyWaffleSwitch(namespace, "test_switch_name", module_name="module1")
self.assertFalse(switch.is_enabled())
self.assertFalse(namespace.is_enabled("test_switch_name"))

# pylint: disable=protected-access
def test_set_request_cache_with_short_name(self):
namespace = WaffleSwitchNamespace("test_namespace")
switch = WaffleSwitch(namespace, "test_switch_name", module_name="module1")
namespace = LegacyWaffleSwitchNamespace("test_namespace")
switch = LegacyWaffleSwitch(namespace, "test_switch_name", module_name="module1")
self.assertFalse(switch._cached_switches.get("test_namespace.test_switch_name"))
namespace.set_request_cache_with_short_name("test_switch_name", True)
self.assertTrue(switch._cached_switches.get("test_namespace.test_switch_name"))
Expand All @@ -45,18 +35,13 @@ def test_set_request_cache_with_short_name(self):
self.assertFalse(switch.is_enabled())


class TestWaffleFlag(TestCase):
class TestLegacyWaffleFlag(TestCase):
"""
Legacy waffle flag tests.
"""

def test_namespaced_flag_name(self):
namespace = WaffleFlagNamespace("namespace")
flag = WaffleFlag(namespace, "flag")
self.assertEqual("namespace.flag", flag.namespaced_flag_name)

def test_default_value(self):
namespace = WaffleFlagNamespace("namespace")
flag = WaffleFlag(namespace, "flag")
namespace = LegacyWaffleFlagNamespace("namespace")
flag = LegacyWaffleFlag(namespace, "flag")
self.assertFalse(flag.is_enabled())
self.assertFalse(namespace.is_flag_active("flag"))
15 changes: 0 additions & 15 deletions edx_toggles/toggles/__future__.py

This file was deleted.

32 changes: 6 additions & 26 deletions edx_toggles/toggles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,10 @@
"""
from .internal.setting_toggle import SettingDictToggle, SettingToggle
from .internal.waffle.flag import NonNamespacedWaffleFlag, WaffleFlag
from .internal.waffle.legacy import WaffleFlag as _LegacyWaffleFlag
from .internal.waffle.legacy import WaffleFlagNamespace as _LegacyWaffleFlagNamespace
from .internal.waffle.legacy import WaffleSwitch as _LegacyWaffleSwitch
from .internal.waffle.legacy import WaffleSwitchNamespace as _LegacyWaffleSwitchNamespace
from .internal.waffle.legacy import (
LegacyWaffleFlag,
LegacyWaffleFlagNamespace,
LegacyWaffleSwitch,
LegacyWaffleSwitchNamespace
)
from .internal.waffle.switch import NonNamespacedWaffleSwitch, WaffleSwitch


# We create new classes instead of simply importing the legacy classes
# for better monitoring of legacy class usage.
class LegacyWaffleFlag(_LegacyWaffleFlag):
def _get_legacy_custom_attribute_name(self):
return "deprecated_compatible_legacy_waffle_class"


class LegacyWaffleFlagNamespace(_LegacyWaffleFlagNamespace):
def _get_legacy_custom_attribute_name(self):
return "deprecated_compatible_legacy_waffle_class"


class LegacyWaffleSwitch(_LegacyWaffleSwitch):
def _get_legacy_custom_attribute_name(self):
return "deprecated_compatible_legacy_waffle_class"


class LegacyWaffleSwitchNamespace(_LegacyWaffleSwitchNamespace):
def _get_legacy_custom_attribute_name(self):
return "deprecated_compatible_legacy_waffle_class"
15 changes: 0 additions & 15 deletions edx_toggles/toggles/internal/waffle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Base waffle toggle classes.
"""

from edx_django_utils.monitoring import set_custom_attribute

from ..base import BaseToggle


Expand All @@ -23,19 +21,6 @@ def __init__(self, name, module_name):
"""
self.validate_name(name)
super().__init__(name, default=False, module_name=module_name)
# Temporarily track usage of undefined module names
if not module_name:
set_custom_attribute(
"deprecated_module_not_supplied",
f"{self.__class__.__name__}[{self.name}]",
)
# Temporarily set a custom attribute to help track usage of the legacy classes.
# Example: edx_toggles.toggles.internal.waffle.legacy=WaffleFlag[some.flag]
# TODO: Remove this custom attribute once internal.waffle.legacy has been removed.
set_custom_attribute(
self.__class__.__module__,
f"{self.__class__.__name__}[{self.name}]",
)

@classmethod
def validate_name(cls, name):
Expand Down
12 changes: 0 additions & 12 deletions edx_toggles/toggles/internal/waffle/flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from weakref import WeakSet

import crum
from edx_django_utils.monitoring import set_custom_attribute
from waffle import flag_is_active

from .base import BaseWaffle
Expand Down Expand Up @@ -83,19 +82,8 @@ def _get_flag_active_no_request(self):
self.name,
)
value = _is_flag_active_for_everyone(self.name)
set_custom_attribute("warn_flag_no_request_return_value", value)
return value

def set_monitor_value(self, _value):
"""
This used to send waffle flag values to monitoring, but is now a no-op. This method is preserved for backward
compatibility.
"""
set_custom_attribute(
"deprecated_waffle_method",
"WaffleFlag[{}].set_monitor_value".format(self.name),
)


class NonNamespacedWaffleFlag(WaffleFlag):
"""
Expand Down
Loading

0 comments on commit 6e90bd2

Please sign in to comment.