From e1bedb83501bb2c6b8b12968a48c87833f70a8bb Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Thu, 9 Nov 2023 21:57:58 +0530 Subject: [PATCH] restores config revision during cache clear #14182 --- netbox/core/management/commands/clearcache.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/netbox/core/management/commands/clearcache.py b/netbox/core/management/commands/clearcache.py index 22843c490..dd95013af 100644 --- a/netbox/core/management/commands/clearcache.py +++ b/netbox/core/management/commands/clearcache.py @@ -1,11 +1,20 @@ from django.core.cache import cache from django.core.management.base import BaseCommand +from extras.models import ConfigRevision + class Command(BaseCommand): """Command to clear the entire cache.""" help = 'Clears the cache.' def handle(self, *args, **kwargs): + # Fetch the current config revision from the cache + config_version = cache.get('config_version') + # Clear the cache cache.clear() self.stdout.write('Cache has been cleared.', ending="\n") + if config_version: + # Activate the current config revision + ConfigRevision.objects.get(id=config_version).activate() + self.stdout.write(f'Config revision ({config_version}) has been restored.', ending="\n")