Commit b62f7249 authored by Loic Bistuer's avatar Loic Bistuer
Browse files

Improved warning message when reloading models. Refs #23621.

Thanks dfunckt and Tim Graham.
parent 8c4ca16c
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -211,7 +211,9 @@ class Apps(object):
            if (model.__name__ == app_models[model_name].__name__ and
                    model.__module__ == app_models[model_name].__module__):
                warnings.warn(
                    "Model '%s.%s' was already registered." % (model_name, app_label),
                    "Model '%s.%s' was already registered. "
                    "Reloading models is not advised as it can lead to inconsistencies, "
                    "most notably with related models." % (model_name, app_label),
                    RuntimeWarning, stacklevel=2)
            else:
                raise RuntimeError(
+4 −1
Original line number Diff line number Diff line
@@ -234,7 +234,10 @@ class AppsTests(TestCase):
            type(str("SouthPonies"), (models.Model,), body)
            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[-1].category, RuntimeWarning))
            self.assertEqual(str(w[-1].message), "Model 'southponies.apps' was already registered.")
            self.assertEqual(str(w[-1].message),
                 "Model 'southponies.apps' was already registered. "
                 "Reloading models is not advised as it can lead to inconsistencies, "
                 "most notably with related models.")

        # If it doesn't appear to be a reloaded module then we expect
        # a RuntimeError.