Device description column is required but unsettable in Custom Scripts #7433

Closed
opened 2025-12-29 20:23:27 +01:00 by adam · 0 comments
Owner

Originally created by @rfdrake on GitHub (Dec 29, 2022).

NetBox version

v3.4.1

Python version

3.10

Steps to Reproduce

Create a script to create devices. In the run() definition add this:

   def run(self, data, commit):
        device = Device(
            name=data["d_name"],
            device_type=data["d_type"],
            site=data["site"],
            device_role=data["role"],
            status=data["status"],
            comments=data["comments"],
        )
        device.save()

That should fail with a "description" of relation "dcim_device" violates not-null constraint.

Then this version:

   def run(self, data, commit):
        device = Device(
            name=data["d_name"],
            device_type=data["d_type"],
            site=data["site"],
            device_role=data["role"],
            status=data["status"],
            comments=data["comments"],
            description="",
        )
        device.save()

Fails with "Device() got an unexpected keyword argument 'description'"

Expected Behavior

We should be able to create a device using the Device() model.

Observed Behavior

This is the error if you don't have a description field:

An exception occurred: IntegrityError: null value in column "description" of relation "dcim_device" violates not-null constraint DETAIL: Failing row contains (9746, 2022-12-29 18:59:15.994142+00, 2022-12-29 18:59:15.994235+00, gw1-test-device, , null, , planned, , 13, 146, null, null, null, null, null, null, 2232, null, null, null, null, null, gw00000001-test-device, {}, null, , null).

Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.NotNullViolation: null value in column "description" of relation "dcim_device" violates not-null constraint
DETAIL:  Failing row contains (9746, 2022-12-29 18:59:15.994142+00, 2022-12-29 18:59:15.994235+00, gw1-test-device, , null, , planned, , 13, 146, null, null, null, null, null, null, 2232, null, null, null, null, null, gw00000001-test-device, {}, null, , null).


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/netbox/netbox/extras/scripts.py", line 464, in _run_script
    script.output = script.run(data=data, commit=commit)
  File "/etc/netbox/scripts/create_device.py", line 42, in run
    device.save()
  File "/opt/netbox/netbox/dcim/models/devices.py", line 831, in save
    super().save(*args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 806, in save
    self.save_base(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 857, in save_base
    updated = self._save_table(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1000, in _save_table
    results = self._do_insert(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1041, in _do_insert
    return manager._insert(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1434, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1621, in execute_sql
    cursor.execute(sql, params)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: null value in column "description" of relation "dcim_device" violates not-null constraint
DETAIL:  Failing row contains (9746, 2022-12-29 18:59:15.994142+00, 2022-12-29 18:59:15.994235+00, gw1-test-device, , null, , planned, , 13, 146, null, null, null, null, null, null, 2232, null, null, null, null, null, gw00000001-test-device, {}, null, , null).

This is the error if you have a description field:

An exception occurred: TypeError: Device() got an unexpected keyword argument 'description'

Traceback (most recent call last):
  File "/opt/netbox/netbox/extras/scripts.py", line 464, in _run_script
    script.output = script.run(data=data, commit=commit)
  File "/etc/netbox/scripts/create_device.py", line 34, in run
    device = Device(
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 559, in __init__
    raise TypeError(
TypeError: Device() got an unexpected keyword argument 'description'

I think the problem is that "description" isn't defined as a column in netbox/dcim/models/devices.py, but I'm not entirely sure because that was just from a quick look. This could also be something I broke in my custom script or whatever.

Please let me know if you need more information.

Originally created by @rfdrake on GitHub (Dec 29, 2022). ### NetBox version v3.4.1 ### Python version 3.10 ### Steps to Reproduce Create a script to create devices. In the run() definition add this: ``` def run(self, data, commit): device = Device( name=data["d_name"], device_type=data["d_type"], site=data["site"], device_role=data["role"], status=data["status"], comments=data["comments"], ) device.save() ``` That should fail with a "description" of relation "dcim_device" violates not-null constraint. Then this version: ``` def run(self, data, commit): device = Device( name=data["d_name"], device_type=data["d_type"], site=data["site"], device_role=data["role"], status=data["status"], comments=data["comments"], description="", ) device.save() ``` Fails with "Device() got an unexpected keyword argument 'description'" ### Expected Behavior We should be able to create a device using the Device() model. ### Observed Behavior This is the error if you don't have a description field: ``` An exception occurred: IntegrityError: null value in column "description" of relation "dcim_device" violates not-null constraint DETAIL: Failing row contains (9746, 2022-12-29 18:59:15.994142+00, 2022-12-29 18:59:15.994235+00, gw1-test-device, , null, , planned, , 13, 146, null, null, null, null, null, null, 2232, null, null, null, null, null, gw00000001-test-device, {}, null, , null). Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) psycopg2.errors.NotNullViolation: null value in column "description" of relation "dcim_device" violates not-null constraint DETAIL: Failing row contains (9746, 2022-12-29 18:59:15.994142+00, 2022-12-29 18:59:15.994235+00, gw1-test-device, , null, , planned, , 13, 146, null, null, null, null, null, null, 2232, null, null, null, null, null, gw00000001-test-device, {}, null, , null). The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/opt/netbox/netbox/extras/scripts.py", line 464, in _run_script script.output = script.run(data=data, commit=commit) File "/etc/netbox/scripts/create_device.py", line 42, in run device.save() File "/opt/netbox/netbox/dcim/models/devices.py", line 831, in save super().save(*args, **kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 806, in save self.save_base( File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 857, in save_base updated = self._save_table( File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1000, in _save_table results = self._do_insert( File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1041, in _do_insert return manager._insert( File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1434, in _insert return query.get_compiler(using=using).execute_sql(returning_fields) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1621, in execute_sql cursor.execute(sql, params) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute return self._execute_with_wrappers( File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers return executor(sql, params, many, context) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute with self.db.wrap_database_errors: File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) django.db.utils.IntegrityError: null value in column "description" of relation "dcim_device" violates not-null constraint DETAIL: Failing row contains (9746, 2022-12-29 18:59:15.994142+00, 2022-12-29 18:59:15.994235+00, gw1-test-device, , null, , planned, , 13, 146, null, null, null, null, null, null, 2232, null, null, null, null, null, gw00000001-test-device, {}, null, , null). ``` This is the error if you have a description field: ``` An exception occurred: TypeError: Device() got an unexpected keyword argument 'description' Traceback (most recent call last): File "/opt/netbox/netbox/extras/scripts.py", line 464, in _run_script script.output = script.run(data=data, commit=commit) File "/etc/netbox/scripts/create_device.py", line 34, in run device = Device( File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 559, in __init__ raise TypeError( TypeError: Device() got an unexpected keyword argument 'description' ``` I think the problem is that "description" isn't defined as a column in netbox/dcim/models/devices.py, but I'm not entirely sure because that was just from a quick look. This could also be something I broke in my custom script or whatever. Please let me know if you need more information.
adam added the type: bug label 2025-12-29 20:23:27 +01:00
adam closed this issue 2025-12-29 20:23:27 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7433