Allow a Pre_Run method in reports #3607

Closed
opened 2025-12-29 18:30:08 +01:00 by adam · 3 comments
Owner

Originally created by @jmanteau on GitHub (Apr 25, 2020).

Environment

  • Python version: 3.7.7
  • NetBox version: 2.8.1

Proposed Functionality

The proposal is to have a pre_run method in reports

Use Case

Reports today are running along the test_* methods defined and closed with the post_run.

If you have several methods that you want to reuse the same python object, there is no clear way to instantiate that in an easy way right now.

Extending the init blocks the Web UI for the time it takes the object initialization to be done and test_aaa is working but inelegant.

The pre_run method will allow users to clearly do the instantiation part of the reports

Database Changes

None

External Dependencies

None

Originally created by @jmanteau on GitHub (Apr 25, 2020). ### Environment * Python version: 3.7.7 * NetBox version: 2.8.1 ### Proposed Functionality **The proposal is to have a pre_run method in reports** ### Use Case Reports today are running along the test_* methods defined and closed with the post_run. If you have several methods that you want to reuse the same python object, there is no clear way to instantiate that in an easy way right now. Extending the __init__ blocks the Web UI for the time it takes the object initialization to be done and test_aaa is working but inelegant. The pre_run method will allow users to clearly do the instantiation part of the reports ### Database Changes None ### External Dependencies None
adam closed this issue 2025-12-29 18:30:08 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 27, 2020):

You can do whatever you want in a report; you have complete control over the source. The run() method is simply the point where control of execution is handed off from NetBox to your script. If you need help writing a custom report, please post to our mailing list.

@jeremystretch commented on GitHub (Apr 27, 2020): You can do whatever you want in a report; you have complete control over the source. The `run()` method is simply the point where control of execution is handed off from NetBox to your script. If you need help writing a custom report, please post to our [mailing list](https://groups.google.com/forum/#!forum/netbox-discuss).
Author
Owner

@jmanteau commented on GitHub (Apr 27, 2020):

Hello,

This feature was to allow in a easier user to have a pre_run method while minimizing the overriding of code from the base Report object.

My use case is when you have "expansive" external calls in term of performance you prefer to do them once in a dedicated method at the start of your report.

In my use case I have preferred to not override the run method to implement the behavior I have made in the rejected PR as it could be blocking for future evolution. I have preferred to implement a test_aaa which will be run first.

The pre_run seemed to be a interesting feature to solve that in a easy and reusable way for other users.

@jmanteau commented on GitHub (Apr 27, 2020): Hello, This feature was to allow in a easier user to have a pre_run method while minimizing the overriding of code from the base Report object. My use case is when you have "expansive" external calls in term of performance you prefer to do them once in a dedicated method at the start of your report. In my use case I have preferred to not override the run method to implement the behavior I have made in the rejected PR as it could be blocking for future evolution. I have preferred to implement a test_aaa which will be run first. The pre_run seemed to be a interesting feature to solve that in a easy and reusable way for other users.
Author
Owner

@aslafy-z commented on GitHub (Aug 5, 2020):

You already implemented a post_run hook, why not adding a pre_run?

@aslafy-z commented on GitHub (Aug 5, 2020): You already implemented a `post_run` hook, why not adding a `pre_run`?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3607