mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
14799 Fix sync of scripts from data source (#15303)
* 14799 fix script creation from data-source * 14799 dont cache module_scripts * 14799 fix sync_classes call
This commit is contained in:
@ -89,6 +89,9 @@ class ManagedFile(SyncedDataMixin, models.Model):
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
||||
if self.data_file and not self.file_path:
|
||||
self.file_path = os.path.basename(self.data_path)
|
||||
|
||||
# Ensure that the file root and path make a unique pair
|
||||
if self._meta.model.objects.filter(file_root=self.file_root, file_path=self.file_path).exclude(pk=self.pk).exists():
|
||||
raise ValidationError(
|
||||
|
@ -108,7 +108,7 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
|
||||
def __str__(self):
|
||||
return self.python_name
|
||||
|
||||
@cached_property
|
||||
@property
|
||||
def module_scripts(self):
|
||||
|
||||
def _get_name(cls):
|
||||
@ -137,9 +137,13 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
|
||||
Syncs the file-based module to the database, adding and removing individual Script objects
|
||||
in the database as needed.
|
||||
"""
|
||||
db_classes = {
|
||||
script.name: script for script in self.scripts.all()
|
||||
}
|
||||
if self.id:
|
||||
db_classes = {
|
||||
script.name: script for script in self.scripts.all()
|
||||
}
|
||||
else:
|
||||
db_classes = {}
|
||||
|
||||
db_classes_set = set(db_classes.keys())
|
||||
module_classes_set = set(self.module_scripts.keys())
|
||||
|
||||
@ -158,10 +162,10 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
|
||||
|
||||
def sync_data(self):
|
||||
super().sync_data()
|
||||
self.sync_classes()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.file_root = ManagedFileRootPathChoices.SCRIPTS
|
||||
self.sync_classes()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user