CustomScripts: 'ContactAssignment' has no attribute 'objects #10140

Closed
opened 2025-12-29 21:27:21 +01:00 by adam · 1 comment
Owner

Originally created by @fneumann-tubs on GitHub (Aug 26, 2024).

Deployment Type

Self-hosted

NetBox Version

v4.0.9

Python Version

3.10

Steps to Reproduce

from extras.scripts import *
from extras.models import *
from tenancy.models import ContactRole, ContactAssignment, Contact, Tenant

class ContactAssignment(Script):

class Meta:
    name = "Kontakt <--> Tenant"
    description = "-"

def run(self, data, commit):
    global list_of_contacts
       
    contact = Contact.objects.get(name="Max Mustermann")
    tenant = Tenant.objects.get(name="TestTenant")
    role = ContactRole.objects.get(name="TestRole")
    ContactAssignment.objects.create(object=tenant, contact=contact, role=role)

Expected Behavior

A new assginment should be created after run this small script between Max Mustermann and TestTenant

When I run the code in the nbshell without a CustomScript, the Contact is assigned to the Tenant.

nbshell_TestAssginment

Observed Behavior

An exception occurred: AttributeError: type object 'ContactAssignment' has no attribute 'objects'

Traceback (most recent call last):
File "/opt/netbox/netbox/extras/scripts.py", line 662, in _run_script
script.output = script.run(data, commit)
File "/opt/netbox/netbox/scripts/Aktualisierungsmanagement.py", line 36, in run
ContactAssignment.objects.create(object=tenant, contact=contact, role=role)
AttributeError: type object 'ContactAssignment' has no attribute 'objects'

Originally created by @fneumann-tubs on GitHub (Aug 26, 2024). ### Deployment Type Self-hosted ### NetBox Version v4.0.9 ### Python Version 3.10 ### Steps to Reproduce from extras.scripts import * from extras.models import * from tenancy.models import ContactRole, ContactAssignment, Contact, Tenant class ContactAssignment(Script): class Meta: name = "Kontakt <--> Tenant" description = "-" def run(self, data, commit): global list_of_contacts contact = Contact.objects.get(name="Max Mustermann") tenant = Tenant.objects.get(name="TestTenant") role = ContactRole.objects.get(name="TestRole") ContactAssignment.objects.create(object=tenant, contact=contact, role=role) ### Expected Behavior A new assginment should be created after run this small script between Max Mustermann and TestTenant When I run the code in the nbshell without a CustomScript, the Contact is assigned to the Tenant. <img width="530" alt="nbshell_TestAssginment" src="https://github.com/user-attachments/assets/3bfc8f46-4a2f-4db1-a039-f415dbe9e29a"> ### Observed Behavior An exception occurred: AttributeError: type object 'ContactAssignment' has no attribute 'objects' Traceback (most recent call last): File "/opt/netbox/netbox/extras/scripts.py", line 662, in _run_script script.output = script.run(data, commit) File "/opt/netbox/netbox/scripts/Aktualisierungsmanagement.py", line 36, in run ContactAssignment.objects.create(object=tenant, contact=contact, role=role) AttributeError: type object 'ContactAssignment' has no attribute 'objects'
adam closed this issue 2025-12-29 21:27:21 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 26, 2024):

This is not a bug in NetBox. Please don't submit bug reports for help writing custom scripts.

@jeremystretch commented on GitHub (Aug 26, 2024): This is not a bug in NetBox. Please don't submit bug reports for help writing custom scripts.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10140