Просмотр исходного кода

Fixes #23696: Rebuild the config context cache in the upgrade command

Jeremy Stretch 7 часов назад
Родитель
Сommit
2f6d3f9cbb
2 измененных файлов с 10 добавлено и 2 удалено
  1. 7 0
      netbox/core/management/commands/upgrade.py
  2. 3 2
      netbox/core/tests/test_management_commands.py

+ 7 - 0
netbox/core/management/commands/upgrade.py

@@ -60,6 +60,13 @@ class Command(BaseCommand):
             out.write("Checking for missing cable paths...")
             out.write("Checking for missing cable paths...")
             call_command('trace_paths', no_input=options['no_input'], stdout=out, stderr=self.stderr)
             call_command('trace_paths', no_input=options['no_input'], stdout=out, stderr=self.stderr)
 
 
+        # Config context cache (writes to the database)
+        if options['readonly']:
+            out.write("Skipping config context cache rebuild.")
+        else:
+            out.write("Caching config context data...")
+            call_command('rebuild_config_context_cache', stdout=out)
+
         # Documentation (filesystem; needs the documentation source tree)
         # Documentation (filesystem; needs the documentation source tree)
         if options['readonly'] and options['build_docs']:
         if options['readonly'] and options['build_docs']:
             out.write("Skipping documentation build.")
             out.write("Skipping documentation build.")

+ 3 - 2
netbox/core/tests/test_management_commands.py

@@ -334,7 +334,7 @@ class UpgradeCommandTest(TestCase):
     def test_full_sequence_order(self):
     def test_full_sequence_order(self):
         seq, _, sub, _ = self._run()
         seq, _, sub, _ = self._run()
         self.assertEqual(seq, [
         self.assertEqual(seq, [
-            'migrate', 'trace_paths',
+            'migrate', 'trace_paths', 'rebuild_config_context_cache',
             'collectstatic', 'remove_stale_contenttypes', 'reindex', 'clearsessions',
             'collectstatic', 'remove_stale_contenttypes', 'reindex', 'clearsessions',
         ])
         ])
         sub.assert_not_called()  # docs not built by default
         sub.assert_not_called()  # docs not built by default
@@ -346,6 +346,7 @@ class UpgradeCommandTest(TestCase):
         sub.assert_not_called()
         sub.assert_not_called()
         self.assertIn('Skipping database migrations.', out)
         self.assertIn('Skipping database migrations.', out)
         self.assertIn('Skipping cable path check.', out)
         self.assertIn('Skipping cable path check.', out)
+        self.assertIn('Skipping config context cache rebuild.', out)
         self.assertIn('Skipping static file collection.', out)
         self.assertIn('Skipping static file collection.', out)
         self.assertIn('Skipping stale content type removal.', out)
         self.assertIn('Skipping stale content type removal.', out)
         self.assertIn('Skipping search index rebuild.', out)
         self.assertIn('Skipping search index rebuild.', out)
@@ -355,7 +356,7 @@ class UpgradeCommandTest(TestCase):
         seq, _, _, _ = self._run(skip_migrations=True, skip_static=True, skip_reindex=True)
         seq, _, _, _ = self._run(skip_migrations=True, skip_static=True, skip_reindex=True)
         self.assertEqual(
         self.assertEqual(
             seq,
             seq,
-            ['trace_paths', 'remove_stale_contenttypes', 'clearsessions'],
+            ['trace_paths', 'rebuild_config_context_cache', 'remove_stale_contenttypes', 'clearsessions'],
         )
         )
 
 
     def test_build_docs_invokes_zensical_when_sources_present(self):
     def test_build_docs_invokes_zensical_when_sources_present(self):