Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Establish a concrete relationship from JobResult to related objects #12068

Closed
jeremystretch opened this issue Mar 27, 2023 · 0 comments
Closed
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@jeremystretch
Copy link
Member

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

@jeremystretch jeremystretch added type: feature Introduction of new functionality to the application status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Mar 27, 2023
@jeremystretch jeremystretch self-assigned this Mar 27, 2023
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Mar 27, 2023
@jeremystretch jeremystretch added this to the v3.5 milestone Mar 27, 2023
jeremystretch added a commit that referenced this issue Mar 28, 2023
…12075)

* Reference database object by GFK when running scripts & reports via UI

* Reference database object by GFK when running scripts & reports via API

* Remove old enqueue_job() method

* Enable filtering jobs by object

* Introduce ObjectJobsView

* Add tabbed views for report & script jobs

* Add object_id to JobSerializer

* Move generic relation to JobsMixin

* Clean up old naming
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

1 participant