Skip to content

Conversation

@Julio-Oliveira-Encora
Copy link
Contributor

@Julio-Oliveira-Encora Julio-Oliveira-Encora commented Jun 4, 2024

Fixes: #16307

It was added to bypass the log message when the status is success, and the message is None.

It was tested using log_success(None, None), log_success("", None), and log_sucess().

…uccess and message is None.

Fixed issue related to edit script ("AttributeError: 'dict' object has no attribute 'append'")
@arthanson
Copy link
Collaborator

@Julio-Oliveira-Encora it looks like log_success() works now with this change, can you please add a note to the documentation on scripts about this.

@arthanson arthanson requested a review from jeremystretch June 10, 2024 15:34
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Julio-Oliveira-Encora have you tested this before submitting the PR? You haven't actually updated the method's signature to make message an optional argument. When calling log_success() in a script, an exception is raised:

Traceback (most recent call last):
  File "/home/jstretch/projects/netbox/netbox/extras/scripts.py", line 658, in _run_script
    script.output = script.run(data, commit)
  File "/home/jstretch/projects/netbox/netbox/scripts/test2.py", line 19, in run
    self.log_success()
TypeError: BaseScript.log_success() missing 1 required positional argument: 'message'

@Julio-Oliveira-Encora
Copy link
Contributor Author

I tested it before submitting the PR. I will check the method's signature and test again.

Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unclear on what the intended goal is here. As it stands, calling log_success(obj=thing) in a custom script does not generate any output. This seems completely pointless, and confusing.

#16307 seems limited to incrementing success counters in reports only; if that's the case, the log_*() methods on the Report class should be modified to call self._log() directly rather than proxying through the log_*() methods on Script, to avoid changing them.

@Julio-Oliveira-Encora
Copy link
Contributor Author

Julio-Oliveira-Encora commented Jun 13, 2024

@jeremystretch About the log methods on the Report class, should I change them this way?

def log_success(self, obj=None, message=None):
     self._log(message, obj, level=LogLevelChoices.LOG_SUCCESS)

Or follow the argument positional from scripts, where message is before obj?

def log_success(self, message, obj=None):
     self._log(message, obj, level=LogLevelChoices.LOG_SUCCESS)

Should I extend this change for all log methods in the class (log_info, log_warning...)?

@Julio-Oliveira-Encora
Copy link
Contributor Author

We could discuss it more because the user is asking for the change for Reports, but maybe he wants to use it in all types of scripts.

The logs for Report class logs were changed to keep the compatibility with the documentation.
@jeremystretch
Copy link
Member

@Julio-Oliveira-Encora I think we went down the wrong path with this a bit. I've submitted an alternate PR (#16697) which I believe addresses the proposal in #16307.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restore ability for scripts to be able to log_success without generating a message

3 participants