Objects passed to self.log_<level> do not get rendered #9818

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

Originally created by @Mailstorm-ctrl on GitHub (Jun 8, 2024).

Deployment Type

Self-hosted

NetBox Version

v4.0.5

Python Version

3.12

Steps to Reproduce

  1. Create a custom script with any kind of log message
  2. Pass an object using obj= or as the second argument
  3. Run the script

Example script:

class examplev2(Script):
        region = ObjectVar(
                model=Region
                )
        def run(self, data, commit):
                def get_child_regions(region, ids=None):
                        if ids is None:
                                ids = []
                        if len(region.children.all()) == 0:
                                self.log_debug(f"No children in {region.name}")
                                ids.append(region.id)
                                return ids
                        for child in region.children.all():
                                self.log_debug(f"Children in {region.name}")
                                ids.append(child.id)
                                get_child_regions(child, ids)
                        return ids
                ids = get_child_regions(data['region'])
                devices = [device.name for device in Device.objects.all() if device.site.region.id in ids]
                self.log_info(f"Devices: {devices}",data['region'])

Expected Behavior

The passed object to be available in the output. In older versions there was a column that had a link to the objects page.

Observed Behavior

No column or mention of the passed object.
image

Originally created by @Mailstorm-ctrl on GitHub (Jun 8, 2024). ### Deployment Type Self-hosted ### NetBox Version v4.0.5 ### Python Version 3.12 ### Steps to Reproduce 1. Create a custom script with any kind of log message 2. Pass an object using `obj=` or as the second argument 3. Run the script Example script: ```python class examplev2(Script): region = ObjectVar( model=Region ) def run(self, data, commit): def get_child_regions(region, ids=None): if ids is None: ids = [] if len(region.children.all()) == 0: self.log_debug(f"No children in {region.name}") ids.append(region.id) return ids for child in region.children.all(): self.log_debug(f"Children in {region.name}") ids.append(child.id) get_child_regions(child, ids) return ids ids = get_child_regions(data['region']) devices = [device.name for device in Device.objects.all() if device.site.region.id in ids] self.log_info(f"Devices: {devices}",data['region']) ``` ### Expected Behavior The passed object to be available in the output. In older versions there was a column that had a link to the objects page. ### Observed Behavior No column or mention of the passed object. ![image](https://github.com/netbox-community/netbox/assets/53045430/a780d1b9-e652-4f94-a290-540bb4e4683a)
adam added the type: bug label 2025-12-29 21:23:08 +01:00
adam closed this issue 2025-12-29 21:23:08 +01:00
Author
Owner

@Mailstorm-ctrl commented on GitHub (Jun 8, 2024):

I mentioned this in https://github.com/netbox-community/netbox/issues/15983 but figured it should have its own report

@Mailstorm-ctrl commented on GitHub (Jun 8, 2024): I mentioned this in https://github.com/netbox-community/netbox/issues/15983 but figured it should have its own report
Author
Owner

@jeremystretch commented on GitHub (Jun 12, 2024):

Sorry for the delay in responding. I think there's some overlap between this and #16307, which has a PR open. I'm going to mark this as blocked for now, then re-evaluate once the fix for #16307 has been merged.

@jeremystretch commented on GitHub (Jun 12, 2024): Sorry for the delay in responding. I think there's some overlap between this and #16307, which has a PR open. I'm going to mark this as blocked for now, then re-evaluate once the fix for #16307 has been merged.
Author
Owner

@Mailstorm-ctrl commented on GitHub (Jun 26, 2024):

This seems to be fixed now. Though I now need to refresh the page to view the results after a script completes. I'll open a separate issue for that

@Mailstorm-ctrl commented on GitHub (Jun 26, 2024): This seems to be fixed now. Though I now need to refresh the page to view the results after a script completes. I'll open a separate issue for that
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9818