Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoSyncRecord inconsistent after file change #14952

Closed
alehaa opened this issue Jan 26, 2024 · 4 comments · Fixed by #15173
Closed

AutoSyncRecord inconsistent after file change #14952

alehaa opened this issue Jan 26, 2024 · 4 comments · Fixed by #15173
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@alehaa
Copy link
Contributor

alehaa commented Jan 26, 2024

Deployment Type

Self-hosted

NetBox Version

v3.7.1

Python Version

3.11

Steps to Reproduce

  1. Create data source TestData:

    Field Value
    Name TestData
    Type git
    URL https://github.com/netbox-community/netbox-plugin-tutorial.git
    enabled yes
  2. Sync data source TestData.

  3. Create export template TestExport:

    Field Value
    Name TestExport
    Content Types Circuits > Circuit (but any will do)
    Data Source TestData
    Data File README.md
    Auto Sync Enabled yes
  4. Edit export template TestExport.

  5. Select Data file tutorial/step01-initial-setup.md and save. (will fail).

  6. Go back to edit form for export template TestExport.

  7. Set Data source, Data file and Auto Sync enabled to null and save.

Expected Behavior

Step 5: Edit succeeds.
Step 7: AutoSyncRecord is removed from database.

Observed Behavior

Step 5: An IntegrityError error is raised, as SyncedDataMixin's save() method won't change existing AutoSyncRecord objects.

Step 7: Edit succeeds, but the related AutoSyncRecord stays in the database. This is due SyncedDataMixin's save() method will remove related AutoSyncRecord objects, but the QuerySet filter uses fields of the object previously set to None in the edit form.

@alehaa alehaa added the type: bug A confirmed report of unexpected behavior in the application label Jan 26, 2024
@jeremystretch
Copy link
Member

jeremystretch commented Jan 29, 2024

Please revise your post above to include explicit instructions. It's not clear exactly which actions are needed to reproduce the bug. Providing a concrete example would be very helpful.

@jeremystretch jeremystretch added the status: revisions needed This issue requires additional information to be actionable label Jan 29, 2024
@alehaa
Copy link
Contributor Author

alehaa commented Feb 1, 2024

@jeremystretch I've updated the instructions to reproduce the issue.

@jeremystretch jeremystretch removed the status: revisions needed This issue requires additional information to be actionable label Feb 1, 2024
@alehaa
Copy link
Contributor Author

alehaa commented Feb 9, 2024

I believe this could be solved easily by altering the delete mechanism in SyncDataMixin to delete all records that should not be present in the database at the end of save() and delete(). I could check this locally and provide a PR if wanted …

@jeremystretch jeremystretch self-assigned this Feb 15, 2024
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows labels Feb 15, 2024
@jeremystretch
Copy link
Member

I believe this could be solved easily by altering the delete mechanism in SyncDataMixin to delete all records that should not be present in the database at the end of save() and delete(). I could check this locally and provide a PR if wanted …

Thanks @alehaa. I think you're on the right track here. We can probably just change get_or_create() to update_or_create() to handle both conditions. I'll submit the change for review in a minute.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
2 participants