Script log functions can completly lock a script when an object is given to the function #4453

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

Originally created by @991jo on GitHub (Jan 12, 2021).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.10.2 and 2.10.3

Steps to Reproduce

  1. Create a Script that logs an object, e.g.
from extras.scripts import Script
from ipam.models import IPAddress

class LockingLog(Script):

    class Meta:

        name = "this log call never returns nor does it raise an exception."

    def run(self, data, commit):
        address = IPAddress.objects.first()
        self.log_info("before")
        self.log_info(address)
        self.log_info("after")
  1. execute the script

Expected Behavior

The script either calls __repr__ or __str__ and logs that output or raises an Exception.

Observed Behavior

The script execution never finishes.
Also the "before" is never logged. When the self.log_info(address) is commented out everything works as intended.

Originally created by @991jo on GitHub (Jan 12, 2021). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reporting reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, please start a discussion instead: https://github.com/netbox-community/netbox/discussions Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.6.8 * NetBox version: 2.10.2 and 2.10.3 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Create a Script that logs an object, e.g. ``` from extras.scripts import Script from ipam.models import IPAddress class LockingLog(Script): class Meta: name = "this log call never returns nor does it raise an exception." def run(self, data, commit): address = IPAddress.objects.first() self.log_info("before") self.log_info(address) self.log_info("after") ``` 2. execute the script <!-- What did you expect to happen? --> ### Expected Behavior The script either calls `__repr__` or `__str__` and logs that output or raises an Exception. <!-- What happened instead? --> ### Observed Behavior The script execution never finishes. Also the "before" is never logged. When the `self.log_info(address)` is commented out everything works as intended.
adam added the pending closure label 2025-12-29 18:36:08 +01:00
adam closed this issue 2025-12-29 18:36:08 +01:00
Author
Owner

@DanSheps commented on GitHub (Jan 13, 2021):

Please upgrade to 2.10.3 and re-test

@DanSheps commented on GitHub (Jan 13, 2021): Please upgrade to 2.10.3 and re-test
Author
Owner

@991jo commented on GitHub (Jan 22, 2021):

okay, I upgraded to 2.10.3, the problem still exists.

@991jo commented on GitHub (Jan 22, 2021): okay, I upgraded to 2.10.3, the problem still exists.
Author
Owner

@jeremystretch commented on GitHub (Feb 8, 2021):

@991jo have you made any further progress on this?

@jeremystretch commented on GitHub (Feb 8, 2021): @991jo have you made any further progress on this?
Author
Owner

@991jo commented on GitHub (Feb 9, 2021):

not really. I was digging around a bit, but haven't found anything.
A wanted to take a look at the objects via nbshell and a problem I ran into was that the Script.objects.all() and .first() methods don't work. I am not sure if that is intended.

>>> Script.objects.all()
Traceback (most recent call last):
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: FEHLER:  Relation »extras_script« existiert nicht
LINE 1: SELECT "extras_script"."id" FROM "extras_script" LIMIT 21
                                         ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 263, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 287, in __iter__
    self._fetch_all()
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/cacheops/query.py", line 283, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
    cursor.execute(sql, params)
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/cacheops/transaction.py", line 93, in execute
    result = self._no_monkey.execute(self, sql, params)
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: FEHLER:  Relation »extras_script« existiert nicht
LINE 1: SELECT "extras_script"."id" FROM "extras_script" LIMIT 21

The psycopg2 error message is in German and basically says

psycopg2.errors.UndefinedTable: ERROR:  Relation »extras_script« does not exist
@991jo commented on GitHub (Feb 9, 2021): not really. I was digging around a bit, but haven't found anything. A wanted to take a look at the objects via nbshell and a problem I ran into was that the `Script.objects.all()` and `.first()` methods don't work. I am not sure if that is intended. ``` >>> Script.objects.all() Traceback (most recent call last): File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) psycopg2.errors.UndefinedTable: FEHLER: Relation »extras_script« existiert nicht LINE 1: SELECT "extras_script"."id" FROM "extras_script" LIMIT 21 ^ The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<console>", line 1, in <module> File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 263, in __repr__ data = list(self[:REPR_OUTPUT_SIZE + 1]) File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 287, in __iter__ self._fetch_all() File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/cacheops/query.py", line 283, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 53, in __iter__ results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size) File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql cursor.execute(sql, params) File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/cacheops/transaction.py", line 93, in execute result = self._no_monkey.execute(self, sql, params) File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 66, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers return executor(sql, params, many, context) File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/utils.py", line 90, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/opt/netbox-2.10.3/venv/lib64/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: FEHLER: Relation »extras_script« existiert nicht LINE 1: SELECT "extras_script"."id" FROM "extras_script" LIMIT 21 ``` The psycopg2 error message is in German and basically says ``` psycopg2.errors.UndefinedTable: ERROR: Relation »extras_script« does not exist ```
Author
Owner

@stale[bot] commented on GitHub (Mar 26, 2021):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Mar 26, 2021): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Apr 14, 2021):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Apr 14, 2021): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4453