Skip to content

Establish a concrete relationship from JobResult to related objects #12068

@jeremystretch

Description

@jeremystretch

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

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: featureIntroduction of new functionality to the application

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions