Script Exception Thrown When Updating an Interface (Any Object?) Across Branches #10977

Closed
opened 2025-12-29 21:38:42 +01:00 by adam · 2 comments
Owner

Originally created by @craized on GitHub (Apr 1, 2025).

Deployment Type

Self-hosted

NetBox Version

v4.2.5

Python Version

3.11

Steps to Reproduce

  1. Create a device on main branch called "Test Device"
  2. Add interface "eth1" to that device with any description
  3. Create a new branch
  4. Activate the new branch
  5. Run a script that attempts to modify the existing interface description
from extras.scripts import *
from dcim.models import Device, Interface

class BranchInterfaceUpdateTest(Script):
    """
    Attempt to update an interface that already exists in main branch by running this script in another branch
    """

    class Meta:
        name = "Branch Interface Update Test"
        description = "Update an interface description across branches"
        scheduling_enabled = False

    def run(self, data, commit):
        
        device = Device.objects.get(name="Test Device")
        interface = Interface.objects.get(name="eth1", device=device)
        self.log_info(
            f'Interface {interface.name} is present'
        )
        interface.description = "Changed description"
        self.log_info(
            f'Interface {interface.name} description has been updated'
        )
        interface.full_clean()
        interface.save()
        self.log_info(
            f'Interface {interface.name} has been saved'
        )

Expected Behavior

The interface description on the local branch is updated

Observed Behavior

An exception is thrown when Interface.save() is called

An exception occurred: AttributeError: 'NoneType' object has no attribute 'items'

Traceback (most recent call last):
  File "/opt/netbox/netbox/extras/jobs.py", line 43, in run_script
    script.output = script.run(data, commit)
  File "/opt/netbox/netbox/scripts/ScriptBranchUpdateTest.py", line 29, in run
    interface.save()
  File "/opt/netbox/netbox/dcim/models/device_components.py", line 957, in save
    super().save(*args, **kwargs)
  File "/opt/netbox/netbox/dcim/models/device_components.py", line 609, in save
    return super().save(*args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 892, in save
    self.save_base(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1013, in save_base
    post_save.send(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/opt/netbox/netbox/core/signals.py", line 94, in handle_changed_object
    objectchange.save()
  File "/opt/netbox/netbox/core/models/change_logging.py", line 136, in save
    return super().save(*args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 892, in save
    self.save_base(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1013, in save_base
    post_save.send(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_branching/signal_receivers.py", line 92, in record_change_diff
    diff.save()
  File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_branching/models/changes.py", line 161, in save
    self._update_conflicts()
  File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_branching/models/changes.py", line 176, in _update_conflicts
    k for k, v in self.original.items()
AttributeError: 'NoneType' object has no attribute 'items'

Image

Originally created by @craized on GitHub (Apr 1, 2025). ### Deployment Type Self-hosted ### NetBox Version v4.2.5 ### Python Version 3.11 ### Steps to Reproduce 1. Create a device on `main` branch called "Test Device" 2. Add interface "eth1" to that device with any description 3. Create a new branch 4. Activate the new branch 5. Run a script that attempts to modify the existing interface description ``` from extras.scripts import * from dcim.models import Device, Interface class BranchInterfaceUpdateTest(Script): """ Attempt to update an interface that already exists in main branch by running this script in another branch """ class Meta: name = "Branch Interface Update Test" description = "Update an interface description across branches" scheduling_enabled = False def run(self, data, commit): device = Device.objects.get(name="Test Device") interface = Interface.objects.get(name="eth1", device=device) self.log_info( f'Interface {interface.name} is present' ) interface.description = "Changed description" self.log_info( f'Interface {interface.name} description has been updated' ) interface.full_clean() interface.save() self.log_info( f'Interface {interface.name} has been saved' ) ``` ### Expected Behavior The interface description on the local branch is updated ### Observed Behavior An exception is thrown when Interface.save() is called ``` An exception occurred: AttributeError: 'NoneType' object has no attribute 'items' Traceback (most recent call last): File "/opt/netbox/netbox/extras/jobs.py", line 43, in run_script script.output = script.run(data, commit) File "/opt/netbox/netbox/scripts/ScriptBranchUpdateTest.py", line 29, in run interface.save() File "/opt/netbox/netbox/dcim/models/device_components.py", line 957, in save super().save(*args, **kwargs) File "/opt/netbox/netbox/dcim/models/device_components.py", line 609, in save return super().save(*args, **kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 892, in save self.save_base( File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1013, in save_base post_save.send( File "/opt/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 189, in send response = receiver(signal=self, sender=sender, **named) File "/opt/netbox/netbox/core/signals.py", line 94, in handle_changed_object objectchange.save() File "/opt/netbox/netbox/core/models/change_logging.py", line 136, in save return super().save(*args, **kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 892, in save self.save_base( File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1013, in save_base post_save.send( File "/opt/netbox/venv/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 189, in send response = receiver(signal=self, sender=sender, **named) File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_branching/signal_receivers.py", line 92, in record_change_diff diff.save() File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_branching/models/changes.py", line 161, in save self._update_conflicts() File "/opt/netbox/venv/lib/python3.10/site-packages/netbox_branching/models/changes.py", line 176, in _update_conflicts k for k, v in self.original.items() AttributeError: 'NoneType' object has no attribute 'items' ``` ![Image](https://github.com/user-attachments/assets/0e2df199-1286-4cef-affc-7a47b901ce0b)
adam closed this issue 2025-12-29 21:38:42 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 3, 2025):

Hi @craized, please note that any bugs which involve a specific NetBox plugin need to be submitted to that plugin's project, not to NetBox itself. Please raise this in the netbox-branching repo.

@jeremystretch commented on GitHub (Apr 3, 2025): Hi @craized, please note that any bugs which involve a specific NetBox plugin need to be submitted to that plugin's project, not to NetBox itself. Please raise this in the [netbox-branching](https://github.com/netboxlabs/netbox-branching) repo.
Author
Owner

@craized commented on GitHub (Apr 3, 2025):

Understood, thx!

On Thu, Apr 3, 2025, 9:25 AM Jeremy Stretch @.***>
wrote:

Hi @craized https://github.com/craized, please note that any bugs which
involve a specific NetBox plugin need to be submitted to that plugin's
project, not to NetBox itself. Please raise this in the netbox-branching
https://github.com/netboxlabs/netbox-branching repo.


Reply to this email directly, view it on GitHub
https://github.com/netbox-community/netbox/issues/19053#issuecomment-2776337575,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAD2A2TPLQ67X2AIVPLUZNT2XVOF3AVCNFSM6AAAAAB2HKYAKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZWGMZTONJXGU
.
You are receiving this because you were mentioned.Message ID:
@.***>
[image: jeremystretch]jeremystretch left a comment
(netbox-community/netbox#19053)
https://github.com/netbox-community/netbox/issues/19053#issuecomment-2776337575

Hi @craized https://github.com/craized, please note that any bugs which
involve a specific NetBox plugin need to be submitted to that plugin's
project, not to NetBox itself. Please raise this in the netbox-branching
https://github.com/netboxlabs/netbox-branching repo.


Reply to this email directly, view it on GitHub
https://github.com/netbox-community/netbox/issues/19053#issuecomment-2776337575,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAD2A2TPLQ67X2AIVPLUZNT2XVOF3AVCNFSM6AAAAAB2HKYAKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZWGMZTONJXGU
.
You are receiving this because you were mentioned.Message ID:
@.***>

@craized commented on GitHub (Apr 3, 2025): Understood, thx! On Thu, Apr 3, 2025, 9:25 AM Jeremy Stretch ***@***.***> wrote: > Hi @craized <https://github.com/craized>, please note that any bugs which > involve a specific NetBox plugin need to be submitted to that plugin's > project, not to NetBox itself. Please raise this in the netbox-branching > <https://github.com/netboxlabs/netbox-branching> repo. > > — > Reply to this email directly, view it on GitHub > <https://github.com/netbox-community/netbox/issues/19053#issuecomment-2776337575>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AAD2A2TPLQ67X2AIVPLUZNT2XVOF3AVCNFSM6AAAAAB2HKYAKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZWGMZTONJXGU> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> > [image: jeremystretch]*jeremystretch* left a comment > (netbox-community/netbox#19053) > <https://github.com/netbox-community/netbox/issues/19053#issuecomment-2776337575> > > Hi @craized <https://github.com/craized>, please note that any bugs which > involve a specific NetBox plugin need to be submitted to that plugin's > project, not to NetBox itself. Please raise this in the netbox-branching > <https://github.com/netboxlabs/netbox-branching> repo. > > — > Reply to this email directly, view it on GitHub > <https://github.com/netbox-community/netbox/issues/19053#issuecomment-2776337575>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AAD2A2TPLQ67X2AIVPLUZNT2XVOF3AVCNFSM6AAAAAB2HKYAKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZWGMZTONJXGU> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> >
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10977