Data Sources remove sync interval
NetBox Edition
NetBox Community
NetBox Version
v4.4.6
Python Version
3.10
Steps to Reproduce
- Create new Data Source (git)
- Leave the Sync Interval blank
- After creation the "Sync" button is active and functional.
- Edit the sync internal and set it to anything.
- Save
- Sync button becomes inactive.
- Edit the sync internal and remove the existing sync interval
- Save
- Status still shows as "Queued" and sync button is still grayed out.
- The job was removed from the Jobs Queue.
- The data source never changes out of Queue state, nor does the Sync button ever become active.
Expected Behavior
Removing Sync Internal should re-enable the Sync button and change the status to Active.
Observed Behavior
Status still shows as Queued and Sync button is grayed out.
as simple fix would be to include the NEW state to:
@property
def ready_for_sync(self):
return self.enabled and self.status not in (
DataSourceStatusChoices.QUEUED,
DataSourceStatusChoices.SYNCING
)
changes to:
@property
def ready_for_sync(self):
return self.enabled and self.status in (
DataSourceStatusChoices.SYNCING,
)
This would allow users to sync their data-sources outside of the scheduled syncs by clicking manually.
As for the status of the data-source. It must be reset to .NEW by checking if the update payload has omited the schedule. This would take require more effort and testing.
I have attempted to fix this by changing the DataSourceForm by adding a clean override method:
def clean(self):
super().clean()
# check if self.sync_interval is null when enabled is True
if not self.cleaned_data.get('sync_interval'):
self.cleaned_data['status'] = DataSourceStatusChoices.NEW
return self.cleaned_data
but the issue with this logic, is that we would have to render the status editable by the user, therefore could cause issues. I tried adding it to self.backend_fields:
self.backend_fields = ["status"]
This unfortunately also renders it as they both call the fieldset method, which currently has no option to hide the inputs.
@jnovinger are you working on a fix for this one?
I have a fix ready, I have applied both logics described in my previous comment.
So my patch does the following:
- Fixes the status update when the user sets a sync intervals.
- Allows the user to sync manually even when a scheduled sync is applied.
@ifoughal, apologies, I had meant to get to this yesterday but ran out of time. Happy to hand it over to you. Thanks!