Lots of Django template exceptions logged with debug level #5739

Closed
opened 2025-12-29 19:32:04 +01:00 by adam · 2 comments
Owner

Originally created by @markkuleinio on GitHub (Dec 7, 2021).

NetBox version

v3.1.0

Python version

3.8

Steps to Reproduce

  1. Logout from NetBox
  2. Configure LOGGING with DEBUG level (see actual configuration below)
  3. Restart netbox and netbox-rq
  4. Login with admin
  5. See the log file with lots of exceptions

Configuration:

import logging.handlers
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'normal': {
            'format': '%(asctime)s %(name)s %(levelname)s: %(message)s'
        },
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.WatchedFileHandler',
            'filename': '/var/log/netbox/netbox.log',
            'formatter': 'normal',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'DEBUG',
        },
        'netbox': {
            'handlers': ['file'],
            'level': 'DEBUG',
        },
    },
}

Expected Behavior

In DEBUG level I expect to have more logging but not very many unhandled exceptions

Observed Behavior

Lots of exceptions, like

KeyError: 'request'
AttributeError: type object 'RequestContext' has no attribute 'request'
ValueError: invalid literal for int() with base 10: 'request'
KeyError: 'value'
AttributeError: 'dict' object has no attribute 'value'
TypeError: 'ObjectChangeTable' object is not subscriptable
AttributeError: 'NoneType' object has no attribute 'get_absolute_url'

Logging texts (before the exception tracebacks):

2021-12-07 15:05:01,288 django.template DEBUG: Exception while resolving variable 'request' in template 'home.html'.
2021-12-07 15:05:01,289 django.template DEBUG: Exception while resolving variable 'value' in template 'home.html'.
2021-12-07 15:05:01,290 django.template DEBUG: Exception while resolving variable 'request' in template 'home.html'.
2021-12-07 15:05:01,291 django.template DEBUG: Exception while resolving variable 'value' in template 'home.html'.
2021-12-07 15:05:01,296 django.template DEBUG: Exception while resolving variable 'page' in template 'inc/table.html'.
2021-12-07 15:05:01,333 django.template DEBUG: Exception while resolving variable 'get_absolute_url' in template 'home.html'.
2021-12-07 15:05:01,337 django.template DEBUG: Exception while resolving variable 'get_absolute_url' in template 'home.html'.
2021-12-07 15:05:01,340 django.template DEBUG: Exception while resolving variable 'get_absolute_url' in template 'home.html'.
2021-12-07 15:05:01,343 django.template DEBUG: Exception while resolving variable 'form' in template 'home.html'.
2021-12-07 15:05:01,346 django.template DEBUG: Exception while resolving variable 'form' in template 'home.html'.

I'm not familiar with Django templates so I cannot tell if emitting exceptions in DEBUG is the normal way of dealing with those.

Full log attached.
netbox.log

Originally created by @markkuleinio on GitHub (Dec 7, 2021). ### NetBox version v3.1.0 ### Python version 3.8 ### Steps to Reproduce 1. Logout from NetBox 2. Configure LOGGING with DEBUG level (see actual configuration below) 3. Restart netbox and netbox-rq 4. Login with admin 5. See the log file with lots of exceptions Configuration: ``` import logging.handlers LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'normal': { 'format': '%(asctime)s %(name)s %(levelname)s: %(message)s' }, }, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.handlers.WatchedFileHandler', 'filename': '/var/log/netbox/netbox.log', 'formatter': 'normal', }, }, 'loggers': { 'django': { 'handlers': ['file'], 'level': 'DEBUG', }, 'netbox': { 'handlers': ['file'], 'level': 'DEBUG', }, }, } ``` ### Expected Behavior In DEBUG level I expect to have more logging but not very many unhandled exceptions ### Observed Behavior Lots of exceptions, like ``` KeyError: 'request' AttributeError: type object 'RequestContext' has no attribute 'request' ValueError: invalid literal for int() with base 10: 'request' KeyError: 'value' AttributeError: 'dict' object has no attribute 'value' TypeError: 'ObjectChangeTable' object is not subscriptable AttributeError: 'NoneType' object has no attribute 'get_absolute_url' ``` Logging texts (before the exception tracebacks): ``` 2021-12-07 15:05:01,288 django.template DEBUG: Exception while resolving variable 'request' in template 'home.html'. 2021-12-07 15:05:01,289 django.template DEBUG: Exception while resolving variable 'value' in template 'home.html'. 2021-12-07 15:05:01,290 django.template DEBUG: Exception while resolving variable 'request' in template 'home.html'. 2021-12-07 15:05:01,291 django.template DEBUG: Exception while resolving variable 'value' in template 'home.html'. 2021-12-07 15:05:01,296 django.template DEBUG: Exception while resolving variable 'page' in template 'inc/table.html'. 2021-12-07 15:05:01,333 django.template DEBUG: Exception while resolving variable 'get_absolute_url' in template 'home.html'. 2021-12-07 15:05:01,337 django.template DEBUG: Exception while resolving variable 'get_absolute_url' in template 'home.html'. 2021-12-07 15:05:01,340 django.template DEBUG: Exception while resolving variable 'get_absolute_url' in template 'home.html'. 2021-12-07 15:05:01,343 django.template DEBUG: Exception while resolving variable 'form' in template 'home.html'. 2021-12-07 15:05:01,346 django.template DEBUG: Exception while resolving variable 'form' in template 'home.html'. ``` I'm not familiar with Django templates so I cannot tell if emitting exceptions in DEBUG is the normal way of dealing with those. Full log attached. [netbox.log](https://github.com/netbox-community/netbox/files/7668525/netbox.log)
adam added the type: bug label 2025-12-29 19:32:04 +01:00
adam closed this issue 2025-12-29 19:32:04 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 7, 2021):

I'm not sure there's anything we need to do here. These are innocuous debug messages resulting from things like referencing an undefined context variable (which is sometimes expected). These messages are not present when logging at the INFO level and above.

@jeremystretch commented on GitHub (Dec 7, 2021): I'm not sure there's anything we need to do here. These are innocuous debug messages resulting from things like referencing an undefined context variable (which is sometimes expected). These messages are not present when logging at the `INFO` level and above.
Author
Owner

@markkuleinio commented on GitHub (Dec 7, 2021):

Ok, feel free to close this if seems fine as is. I already opened a discussion about finding a way to log user creations, apparently DEBUG level was not it 👍

@markkuleinio commented on GitHub (Dec 7, 2021): Ok, feel free to close this if seems fine as is. I already opened a discussion about finding a way to log user creations, apparently DEBUG level was not it 👍
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5739