Establish a concrete relationship from JobResult to related objects #7802

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

Originally created by @jeremystretch on GitHub (Mar 27, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.4.6

Feature type

Data model extension

Proposed functionality

The JobResult model current has a ForeignKey field to ContentType, which enables associating an instance with a particular type of NetBox model. It also has a name field to indicate the object's name, however this is not a concrete relationship in the database. This is due to the limitation of scripts and reports not being tracked as database objects.

This FR proposes the additional of an object ID field to complement the object type field, which will enable GenericForeignKey assignments for JobResults. This is possible thanks to the implementation of #11890, which introduces "real" database models representing reports and scripts.

The following changes are proposed for the JobResult model:

  1. Rename obj_type to object_type for consistency with other NetBox models using GFK.
  2. Add an object_id integer field.
  3. Add a GenericForeignKey field leveraging both of the above. Object types will be limited to those models inheriting from JobResultsMixin.

We'll keep the name field as an optional field: It can be used to differentiate among jobs pertaining to the same object. For example, we can expect a ScriptModule containing multiple scripts to have separate jobs for each script.

Use case

Introducing a database relationship between a job and its assigned object enables more robust and efficient correlation and management of jobs. For example, we'll be able to pull all jobs pertaining to a specific script via it's module:

ScriptModule.jobs.filter(name='myscript1')

Database changes

No response

External dependencies

No response

Originally created by @jeremystretch on GitHub (Mar 27, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.4.6 ### Feature type Data model extension ### Proposed functionality The JobResult model current has a ForeignKey field to ContentType, which enables associating an instance with a particular type of NetBox model. It also has a `name` field to indicate the object's name, however this is not a concrete relationship in the database. This is due to the limitation of scripts and reports not being tracked as database objects. This FR proposes the additional of an object ID field to complement the object type field, which will enable GenericForeignKey assignments for JobResults. This is possible thanks to the implementation of #11890, which introduces "real" database models representing reports and scripts. The following changes are proposed for the JobResult model: 1. Rename `obj_type` to `object_type` for consistency with other NetBox models using GFK. 2. Add an `object_id` integer field. 3. Add a GenericForeignKey field leveraging both of the above. Object types will be limited to those models inheriting from `JobResultsMixin`. We'll keep the `name` field as an optional field: It can be used to differentiate among jobs pertaining to the same object. For example, we can expect a ScriptModule containing multiple scripts to have separate jobs for each script. ### Use case Introducing a database relationship between a job and its assigned object enables more robust and efficient correlation and management of jobs. For example, we'll be able to pull all jobs pertaining to a specific script via it's module: ``` ScriptModule.jobs.filter(name='myscript1') ``` ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 20:28:22 +01:00
adam closed this issue 2025-12-29 20:28:23 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7802