From b32fc5094747262808c586b2ea4f2c5ebf8a400b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9gis=20Behmo?= <regis@behmo.com>
Date: Thu, 5 Nov 2020 08:32:56 +0100
Subject: [PATCH] Improve monitoring of waffle deprecation with custom
 attributes

We observe a lot of deprecation warnings using the
"deprecated_waffle_utils" custom attribute. To make it easier to track
these items, we add the waffle flag/namespace name to the custom
attribute.
---
 .../core/djangoapps/waffle_utils/__init__.py  | 24 +++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/openedx/core/djangoapps/waffle_utils/__init__.py b/openedx/core/djangoapps/waffle_utils/__init__.py
index 3b87959fd3d..24376401322 100644
--- a/openedx/core/djangoapps/waffle_utils/__init__.py
+++ b/openedx/core/djangoapps/waffle_utils/__init__.py
@@ -21,8 +21,8 @@ class WaffleSwitchNamespace(BaseWaffleSwitchNamespace):
     Deprecated class: instead, use edx_toggles.toggles.WaffleSwitchNamespace.
     """
 
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
+    def __init__(self, name, log_prefix=None):
+        super().__init__(name, log_prefix=log_prefix)
         warnings.warn(
             (
                 "Importing WaffleSwitchNamespace from waffle_utils is deprecated. Instead, import from"
@@ -31,7 +31,7 @@ class WaffleSwitchNamespace(BaseWaffleSwitchNamespace):
             DeprecationWarning,
             stacklevel=2,
         )
-        set_custom_attribute("deprecated_waffle_utils", "WaffleSwitchNamespace")
+        set_custom_attribute("deprecated_waffle_utils", "WaffleSwitchNamespace[{}]".format(name))
 
     @contextmanager
     def override(self, switch_name, active=True):
@@ -62,14 +62,14 @@ class WaffleSwitch(BaseWaffleSwitch):
     Deprecated class: instead, use edx_toggles.toggles.WaffleSwitch.
     """
 
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
+    def __init__(self, waffle_namespace, switch_name, module_name=None):
+        super().__init__(waffle_namespace, switch_name, module_name=module_name)
         warnings.warn(
             "Importing WaffleSwitch from waffle_utils is deprecated. Instead, import from edx_toggles.toggles.",
             DeprecationWarning,
             stacklevel=2,
         )
-        set_custom_attribute("deprecated_waffle_utils", "WaffleSwitch")
+        set_custom_attribute("deprecated_waffle_utils", "WaffleSwitch[{}]".format(self.name))
 
 
 class WaffleFlagNamespace(BaseWaffleFlagNamespace):
@@ -77,14 +77,14 @@ class WaffleFlagNamespace(BaseWaffleFlagNamespace):
     Deprecated class: instead, use edx_toggles.toggles.WaffleFlagNamespace.
     """
 
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
+    def __init__(self, name, log_prefix=None):
+        super().__init__(name, log_prefix=log_prefix)
         warnings.warn(
             "Importing WaffleFlagNamespace from waffle_utils is deprecated. Instead, import from edx_toggles.toggles.",
             DeprecationWarning,
             stacklevel=2,
         )
-        set_custom_attribute("deprecated_waffle_utils", "WaffleFlagNamespace")
+        set_custom_attribute("deprecated_waffle_utils", "WaffleFlagNamespace[{}]".format(name))
 
 
 class WaffleFlag(BaseWaffleFlag):
@@ -92,14 +92,14 @@ class WaffleFlag(BaseWaffleFlag):
     Deprecated class: instead, use edx_toggles.toggles.WaffleFlag.
     """
 
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
+    def __init__(self, waffle_namespace, flag_name, module_name=None):
+        super().__init__(waffle_namespace, flag_name, module_name=module_name)
         warnings.warn(
             "Importing WaffleFlag from waffle_utils is deprecated. Instead, import from edx_toggles.toggles.",
             DeprecationWarning,
             stacklevel=2,
         )
-        set_custom_attribute("deprecated_waffle_utils", "WaffleFlag")
+        set_custom_attribute("deprecated_waffle_utils", "WaffleFlag[{}]".format(self.name))
 
     @contextmanager
     def override(self, active=True):
-- 
GitLab