Repository: django-cms/django-cms

Issue:
urls_need_reloading signal not firing when slugs are changed
On 3.0.6, 3.0.7 and master (dabf832a10a7f0687610fb33d3103bcb984d3973) the `urls_need_reloading` signal does not fire in the following cases. But it should.:
- the slug of an app-hooked page changes (and the change is published)
- the app-hooked page is moved
- the slug of a parent page changes (and the change is published)

This might be a regression from #2911 .



Discussion:

Resolving patch:
diff --git a/cms/signals/apphook.py b/cms/signals/apphook.py
--- a/cms/signals/apphook.py
+++ b/cms/signals/apphook.py
@@ -41,12 +41,25 @@ def apphook_post_title_checker(instance, **kwargs):
     old_title = getattr(instance, '_old_data', None)
     if not old_title:
         if instance.page.application_urls:
-            request_finished.connect(trigger_restart, dispatch_uid=DISPATCH_UID)
+            request_finished.connect(
+                trigger_restart,
+                dispatch_uid=DISPATCH_UID
+            )
     else:
         old_values = (
-            old_title.published, old_title.page.application_urls, old_title.page.application_namespace, old_title.path)
+            old_title.published,
+            old_title.page.application_urls,
+            old_title.page.application_namespace,
+            old_title.path,
+            old_title.slug,
+        )
         new_values = (
-            instance.published, instance.page.application_urls, instance.page.application_namespace, instance.path)
+            instance.published,
+            instance.page.application_urls,
+            instance.page.application_namespace,
+            instance.path,
+            instance.slug,
+        )
         if old_values != new_values and (old_values[2] or new_values[2]):
             request_finished.connect(trigger_restart, dispatch_uid=DISPATCH_UID)
 


Test patch:
diff --git a/cms/tests/signals.py b/cms/tests/signals.py
--- a/cms/tests/signals.py
+++ b/cms/tests/signals.py
@@ -6,7 +6,6 @@
 
 from cms.api import create_page
 from cms.signals import urls_need_reloading
-from cms.utils.compat.dj import get_user_model
 
 
 class SignalTester(object):
@@ -29,21 +28,54 @@ def signal_tester(signal):
         signal.disconnect(env, weak=True)
     
 
-
 class SignalTests(TestCase):
     def test_urls_need_reloading_signal_create(self):
-        superuser = get_user_model().objects.create_superuser('admin', 'admin@admin.com', 'admin')
         with signal_tester(urls_need_reloading) as env:
-            create_page("apphooked-page", "nav_playground.html", "en",
-                created_by=superuser, published=True, apphook="SampleApp")
+            self.client.get('/')
+            self.assertEqual(env.call_count, 0)
+            create_page(
+                "apphooked-page",
+                "nav_playground.html",
+                "en",
+                published=True,
+                apphook="SampleApp",
+                apphook_namespace="test"
+            )
             self.client.get('/')
             self.assertEqual(env.call_count, 1)
 
     def test_urls_need_reloading_signal_delete(self):
-        superuser = get_user_model().objects.create_superuser('admin', 'admin@admin.com', 'admin')
-        page = create_page("apphooked-page", "nav_playground.html", "en",
-            created_by=superuser, published=True, apphook="SampleApp")
         with signal_tester(urls_need_reloading) as env:
+            self.client.get('/')
+            self.assertEqual(env.call_count, 0)
+            page = create_page(
+                "apphooked-page",
+                "nav_playground.html",
+                "en",
+                published=True,
+                apphook="SampleApp",
+                apphook_namespace="test"
+            )
             page.delete()
             self.client.get('/')
             self.assertEqual(env.call_count, 1)
+
+    def test_urls_need_reloading_signal_change_slug(self):
+        with signal_tester(urls_need_reloading) as env:
+            self.assertEqual(env.call_count, 0)
+            page = create_page(
+                "apphooked-page",
+                "nav_playground.html",
+                "en",
+                published=True,
+                apphook="SampleApp",
+                apphook_namespace="test"
+            )
+            self.client.get('/')
+            self.assertEqual(env.call_count, 1)
+            title = page.title_set.get(language="en")
+            title.slug += 'test'
+            title.save()
+            page.publish('en')
+            self.client.get('/')
+            self.assertEqual(env.call_count, 2)