UserConfig not automatically created for LDAP-authenticated user #4130

Closed
opened 2025-12-29 18:33:21 +01:00 by adam · 7 comments
Owner

Originally created by @exiz01 on GitHub (Sep 23, 2020).

Environment

  • Python version: 3.6.9
  • NetBox version: 2.9.3

Steps to Reproduce

  1. With a fresh install of netbox 2.9.3 we imported and upgraded a database from version 2.8.3
  2. Set LDAP authentication using this guide
  3. When I log in for the first time with a new LDAP user this error is displayed
    Apparently the error may be related to this function inside netbox/users/models.py
    def create_userconfig(instance, created, **kwargs):
    if created:
    UserConfig(user=instance).save()

Expected Behavior

The user's config inside users_userconfig table should be created.

Observed Behavior

When you log in for the first time this is displayed.

image

If I log out and log in again with the same user no error is displayed until I try to access some object, for example, if I access to devices section, then this is displayed.

Screenshot from 2020-09-22 16-52-42

As an observation, we found that no record is created for the new user inside users_userconfig table. Actually, we tried creating the record manually and when we did this the error disappeared.

Originally created by @exiz01 on GitHub (Sep 23, 2020). ## Environment * Python version: 3.6.9 * NetBox version: 2.9.3 ### Steps to Reproduce 1. With a fresh install of netbox 2.9.3 we imported and upgraded a database from version 2.8.3 2. Set LDAP authentication using [this guide](https://netbox.readthedocs.io/en/stable/installation/6-ldap/) 3. When I log in for the first time with a new LDAP user [this error is displayed](https://i.imgur.com/tbLCzLP.png) Apparently the error may be related to this function inside netbox/users/models.py `def create_userconfig(instance, created, **kwargs):` ` if created:` ` UserConfig(user=instance).save()` <!-- What did you expect to happen? --> ### Expected Behavior The user's config inside users_userconfig table should be created. <!-- What happened instead? --> ### Observed Behavior When you log in for the first time this is displayed. ![image](https://user-images.githubusercontent.com/25999829/93944792-e277ab00-fcf2-11ea-8498-fc44e498d42c.png) If I log out and log in again with the same user no error is displayed until I try to access some object, for example, if I access to devices section, then this is displayed. ![Screenshot from 2020-09-22 16-52-42](https://user-images.githubusercontent.com/25999829/93945417-16070500-fcf4-11ea-804d-317628d4a92d.png) As an observation, we found that no record is created for the new user inside users_userconfig table. Actually, we tried creating the record manually and when we did this the error disappeared.
adam closed this issue 2025-12-29 18:33:21 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 23, 2020):

I'm not clear on how the post_save signal can be passing an instance with no primary key assigned. Can you please capture and post the full stack trace from the IntegrityError exception? (Set DEBUG = True in configuration.py and restart NetBox first.)

@jeremystretch commented on GitHub (Sep 23, 2020): I'm not clear on how the `post_save` signal can be passing an instance with no primary key assigned. Can you please capture and post the full stack trace from the IntegrityError exception? (Set `DEBUG = True` in `configuration.py` and restart NetBox first.)
Author
Owner

@exiz01 commented on GitHub (Sep 23, 2020):

This is the first error I mentioned (I changed the URL for privacy matters)

Environment:

Request Method: POST
Request URL: https://0.0.0.0/login/

Django Version: 3.1
Python Version: 3.6.9
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'cacheops',
'corsheaders',
'debug_toolbar',
'django_filters',
'django_tables2',
'django_prometheus',
'mptt',
'rest_framework',
'taggit',
'timezone_field',
'circuits',
'dcim',
'ipam',
'extras',
'secrets',
'tenancy',
'users',
'utilities',
'virtualization',
'django_rq',
'drf_yasg']
Installed Middleware:
['debug_toolbar.middleware.DebugToolbarMiddleware',
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'utilities.middleware.ExceptionHandlingMiddleware',
'utilities.middleware.RemoteUserMiddleware',
'utilities.middleware.LoginRequiredMiddleware',
'utilities.middleware.APIVersionMiddleware',
'extras.middleware.ObjectChangeMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware']

Traceback (most recent call last):
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)

The above exception (null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, {}, 92).
) was the direct cause of the following exception:
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 73, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/decorators/debug.py", line 89, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "/opt/netbox/netbox/users/views.py", line 36, in dispatch
return super().dispatch(*args, **kwargs)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 101, in dispatch
return handler(request, *args, **kwargs)
File "/opt/netbox/netbox/users/views.py", line 53, in post
if form.is_valid():
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 177, in is_valid
return self.is_bound and not self.errors
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 172, in errors
self.full_clean()
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 375, in full_clean
self._clean_form()
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 402, in _clean_form
cleaned_data = self.clean()
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 215, in clean
self.user_cache = authenticate(self.request, username=username, password=password)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/contrib/auth/init.py", line 73, in authenticate
user = backend.authenticate(request, **credentials)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django_auth_ldap/backend.py", line 153, in authenticate
user = self.authenticate_ldap_user(ldap_user, password)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django_auth_ldap/backend.py", line 211, in authenticate_ldap_user
return ldap_user.authenticate(password)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django_auth_ldap/backend.py", line 355, in authenticate
self._get_or_create_user()
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django_auth_ldap/backend.py", line 632, in _get_or_create_user
self._user.save()
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 67, in save
super().save(*args, **kwargs)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 751, in save
force_update=force_update, update_fields=update_fields)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 800, in save_base
update_fields=update_fields, raw=raw, using=using,
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 179, in send
for receiver in self._live_receivers(sender)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 179, in
for receiver in self._live_receivers(sender)
File "/opt/netbox/netbox/users/models.py", line 171, in create_userconfig
UserConfig(user=instance).save()
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 751, in save
force_update=force_update, update_fields=update_fields)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 789, in save_base
force_update, using, update_fields,
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 892, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 932, in _do_insert
using=using, raw=raw,
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/query.py", line 1249, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1395, in execute_sql
cursor.execute(sql, params)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 198, in execute
return self._record(self.cursor.execute, sql, params)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 133, in _record
return method(sql, params)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/cacheops/transaction.py", line 93, in execute
result = self._no_monkey.execute(self, sql, params)
File "/opt/netbox-2.9.3/venv/lib/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.9.3/venv/lib/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.9.3/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/opt/netbox-2.9.3/venv/lib/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.9.3/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)

Exception Type: IntegrityError at /login/
Exception Value: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, {}, 92).

And the second one

Environment:

Request Method: GET
Request URL: https://0.0.0.0/dcim/devices/

Django Version: 3.1
Python Version: 3.6.9
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'cacheops',
'corsheaders',
'debug_toolbar',
'django_filters',
'django_tables2',
'django_prometheus',
'mptt',
'rest_framework',
'taggit',
'timezone_field',
'circuits',
'dcim',
'ipam',
'extras',
'secrets',
'tenancy',
'users',
'utilities',
'virtualization',
'django_rq',
'drf_yasg']
Installed Middleware:
['debug_toolbar.middleware.DebugToolbarMiddleware',
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'utilities.middleware.ExceptionHandlingMiddleware',
'utilities.middleware.RemoteUserMiddleware',
'utilities.middleware.LoginRequiredMiddleware',
'utilities.middleware.APIVersionMiddleware',
'extras.middleware.ObjectChangeMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware']

Traceback (most recent call last):
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 73, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/netbox/netbox/utilities/views.py", line 123, in dispatch
return super().dispatch(request, *args, **kwargs)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 101, in dispatch
return handler(request, *args, **kwargs)
File "/opt/netbox/netbox/utilities/views.py", line 306, in get
columns = request.user.config.get(f"tables.{self.table.name}.columns")
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/utils/functional.py", line 241, in inner
return func(self._wrapped, *args)
File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 424, in get
self.related.get_accessor_name()

Exception Type: RelatedObjectDoesNotExist at /dcim/devices/
Exception Value: User has no config.

@exiz01 commented on GitHub (Sep 23, 2020): This is the first error I mentioned (I changed the URL for privacy matters) > Environment: > > > Request Method: POST > Request URL: https://0.0.0.0/login/ > > Django Version: 3.1 > Python Version: 3.6.9 > Installed Applications: > ['django.contrib.admin', > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.messages', > 'django.contrib.staticfiles', > 'django.contrib.humanize', > 'cacheops', > 'corsheaders', > 'debug_toolbar', > 'django_filters', > 'django_tables2', > 'django_prometheus', > 'mptt', > 'rest_framework', > 'taggit', > 'timezone_field', > 'circuits', > 'dcim', > 'ipam', > 'extras', > 'secrets', > 'tenancy', > 'users', > 'utilities', > 'virtualization', > 'django_rq', > 'drf_yasg'] > Installed Middleware: > ['debug_toolbar.middleware.DebugToolbarMiddleware', > 'django_prometheus.middleware.PrometheusBeforeMiddleware', > 'corsheaders.middleware.CorsMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.common.CommonMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > 'django.middleware.clickjacking.XFrameOptionsMiddleware', > 'django.middleware.security.SecurityMiddleware', > 'utilities.middleware.ExceptionHandlingMiddleware', > 'utilities.middleware.RemoteUserMiddleware', > 'utilities.middleware.LoginRequiredMiddleware', > 'utilities.middleware.APIVersionMiddleware', > 'extras.middleware.ObjectChangeMiddleware', > 'django_prometheus.middleware.PrometheusAfterMiddleware'] > > > > Traceback (most recent call last): > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute > return self.cursor.execute(sql, params) > > The above exception (null value in column "id" violates not-null constraint > DETAIL: Failing row contains (null, {}, 92). > ) was the direct cause of the following exception: > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner > response = get_response(request) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response > response = wrapped_callback(request, *callback_args, **callback_kwargs) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 73, in view > return self.dispatch(request, *args, **kwargs) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/utils/decorators.py", line 43, in _wrapper > return bound_method(*args, **kwargs) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/decorators/debug.py", line 89, in sensitive_post_parameters_wrapper > return view(request, *args, **kwargs) > File "/opt/netbox/netbox/users/views.py", line 36, in dispatch > return super().dispatch(*args, **kwargs) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 101, in dispatch > return handler(request, *args, **kwargs) > File "/opt/netbox/netbox/users/views.py", line 53, in post > if form.is_valid(): > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 177, in is_valid > return self.is_bound and not self.errors > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 172, in errors > self.full_clean() > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 375, in full_clean > self._clean_form() > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 402, in _clean_form > cleaned_data = self.clean() > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 215, in clean > self.user_cache = authenticate(self.request, username=username, password=password) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 73, in authenticate > user = backend.authenticate(request, **credentials) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django_auth_ldap/backend.py", line 153, in authenticate > user = self.authenticate_ldap_user(ldap_user, password) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django_auth_ldap/backend.py", line 211, in authenticate_ldap_user > return ldap_user.authenticate(password) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django_auth_ldap/backend.py", line 355, in authenticate > self._get_or_create_user() > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django_auth_ldap/backend.py", line 632, in _get_or_create_user > self._user.save() > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 67, in save > super().save(*args, **kwargs) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 751, in save > force_update=force_update, update_fields=update_fields) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 800, in save_base > update_fields=update_fields, raw=raw, using=using, > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 179, in send > for receiver in self._live_receivers(sender) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 179, in <listcomp> > for receiver in self._live_receivers(sender) > File "/opt/netbox/netbox/users/models.py", line 171, in create_userconfig > UserConfig(user=instance).save() > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 751, in save > force_update=force_update, update_fields=update_fields) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 789, in save_base > force_update, using, update_fields, > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 892, in _save_table > results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/base.py", line 932, in _do_insert > using=using, raw=raw, > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method > return getattr(self.get_queryset(), name)(*args, **kwargs) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/query.py", line 1249, in _insert > return query.get_compiler(using=using).execute_sql(returning_fields) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1395, in execute_sql > cursor.execute(sql, params) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 198, in execute > return self._record(self.cursor.execute, sql, params) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 133, in _record > return method(sql, params) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 98, in execute > return super().execute(sql, params) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/cacheops/transaction.py", line 93, in execute > result = self._no_monkey.execute(self, sql, params) > File "/opt/netbox-2.9.3/venv/lib/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.9.3/venv/lib/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.9.3/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute > return self.cursor.execute(sql, params) > File "/opt/netbox-2.9.3/venv/lib/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.9.3/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute > return self.cursor.execute(sql, params) > > Exception Type: IntegrityError at /login/ > Exception Value: null value in column "id" violates not-null constraint > DETAIL: Failing row contains (null, {}, 92). > And the second one > Environment: > > > Request Method: GET > Request URL: https://0.0.0.0/dcim/devices/ > > Django Version: 3.1 > Python Version: 3.6.9 > Installed Applications: > ['django.contrib.admin', > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.messages', > 'django.contrib.staticfiles', > 'django.contrib.humanize', > 'cacheops', > 'corsheaders', > 'debug_toolbar', > 'django_filters', > 'django_tables2', > 'django_prometheus', > 'mptt', > 'rest_framework', > 'taggit', > 'timezone_field', > 'circuits', > 'dcim', > 'ipam', > 'extras', > 'secrets', > 'tenancy', > 'users', > 'utilities', > 'virtualization', > 'django_rq', > 'drf_yasg'] > Installed Middleware: > ['debug_toolbar.middleware.DebugToolbarMiddleware', > 'django_prometheus.middleware.PrometheusBeforeMiddleware', > 'corsheaders.middleware.CorsMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.common.CommonMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > 'django.middleware.clickjacking.XFrameOptionsMiddleware', > 'django.middleware.security.SecurityMiddleware', > 'utilities.middleware.ExceptionHandlingMiddleware', > 'utilities.middleware.RemoteUserMiddleware', > 'utilities.middleware.LoginRequiredMiddleware', > 'utilities.middleware.APIVersionMiddleware', > 'extras.middleware.ObjectChangeMiddleware', > 'django_prometheus.middleware.PrometheusAfterMiddleware'] > > > > Traceback (most recent call last): > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner > response = get_response(request) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response > response = wrapped_callback(request, *callback_args, **callback_kwargs) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 73, in view > return self.dispatch(request, *args, **kwargs) > File "/opt/netbox/netbox/utilities/views.py", line 123, in dispatch > return super().dispatch(request, *args, **kwargs) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 101, in dispatch > return handler(request, *args, **kwargs) > File "/opt/netbox/netbox/utilities/views.py", line 306, in get > columns = request.user.config.get(f"tables.{self.table.__name__}.columns") > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/utils/functional.py", line 241, in inner > return func(self._wrapped, *args) > File "/opt/netbox-2.9.3/venv/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 424, in __get__ > self.related.get_accessor_name() > > Exception Type: RelatedObjectDoesNotExist at /dcim/devices/ > Exception Value: User has no config. >
Author
Owner

@jeremystretch commented on GitHub (Sep 28, 2020):

Exception Type: IntegrityError at /login/
Exception Value: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, {}, 92).

This suggests that the UserConfig object is being created with its ID set to null for some reason. Can you confirm that you've not made any modifications to the underlying SQL database? Please post the output of the following:

$ ./manage.py dbshell
netbox=> \d users_userconfig

Also, are you able to replicate the error without involving LDAP (by creating a user locally)?

@jeremystretch commented on GitHub (Sep 28, 2020): ``` Exception Type: IntegrityError at /login/ Exception Value: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, {}, 92). ``` This suggests that the UserConfig object is being created with its ID set to `null` for some reason. Can you confirm that you've not made any modifications to the underlying SQL database? Please post the output of the following: ``` $ ./manage.py dbshell netbox=> \d users_userconfig ``` Also, are you able to replicate the error without involving LDAP (by creating a user locally)?
Author
Owner

@exiz01 commented on GitHub (Sep 28, 2020):

Here is the output you requested:

          Table "public.users_userconfig"
 Column  |  Type   | Collation | Nullable | Default 
---------+---------+-----------+----------+---------
 id      | integer |           | not null | 
 data    | jsonb   |           | not null | 
 user_id | integer |           | not null | 
Indexes:
    "users_userconfig_pkey" PRIMARY KEY, btree (id)
    "users_userconfig_user_id_key" UNIQUE CONSTRAINT, btree (user_id)
Foreign-key constraints:
    "users_userconfig_user_id_afd44184_fk_auth_user_id" FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED

Yes, I tried to create a local user from the web interface and this happened:

Screenshot from 2020-09-28 12-04-04

Screenshot from 2020-09-28 12-03-33

@exiz01 commented on GitHub (Sep 28, 2020): Here is the output you requested: ``` Table "public.users_userconfig" Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------- id | integer | | not null | data | jsonb | | not null | user_id | integer | | not null | Indexes: "users_userconfig_pkey" PRIMARY KEY, btree (id) "users_userconfig_user_id_key" UNIQUE CONSTRAINT, btree (user_id) Foreign-key constraints: "users_userconfig_user_id_afd44184_fk_auth_user_id" FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED ``` Yes, I tried to create a local user from the web interface and this happened: ![Screenshot from 2020-09-28 12-04-04](https://user-images.githubusercontent.com/25999829/94469165-dbcdb580-0182-11eb-8bed-f487966fe748.png) ![Screenshot from 2020-09-28 12-03-33](https://user-images.githubusercontent.com/25999829/94469163-db351f00-0182-11eb-89d4-aef3a696a574.png)
Author
Owner

@jeremystretch commented on GitHub (Sep 28, 2020):

You seem to be missing the sequence on the id column, which is very strange. Here's what the table should look like:

netbox=> \d users_userconfig
                             Table "public.users_userconfig"
 Column  |  Type   | Collation | Nullable |                   Default                    
---------+---------+-----------+----------+----------------------------------------------
 id      | integer |           | not null | nextval('users_userconfig_id_seq'::regclass)
 data    | jsonb   |           | not null | 
 user_id | integer |           | not null | 
Indexes:
    "users_userconfig_pkey" PRIMARY KEY, btree (id)
    "users_userconfig_user_id_key" UNIQUE CONSTRAINT, btree (user_id)
Foreign-key constraints:
    "users_userconfig_user_id_afd44184_fk_auth_user_id" FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED

SELECT * FROM information_schema.sequences WHERE sequence_name='users_userconfig_id_seq'; should return the sequence.

I can't imagine how you'd get to this state without someone having directly manipulated the PostgreSQL database to drop the sequence. You can try to restore it manually, but I'd suggest first determining how it happened, as there may be other issues lurking. Please post to our mailing list if you require any further assistance.

@jeremystretch commented on GitHub (Sep 28, 2020): You seem to be missing the sequence on the `id` column, which is _very_ strange. Here's what the table should look like: ``` netbox=> \d users_userconfig Table "public.users_userconfig" Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+---------------------------------------------- id | integer | | not null | nextval('users_userconfig_id_seq'::regclass) data | jsonb | | not null | user_id | integer | | not null | Indexes: "users_userconfig_pkey" PRIMARY KEY, btree (id) "users_userconfig_user_id_key" UNIQUE CONSTRAINT, btree (user_id) Foreign-key constraints: "users_userconfig_user_id_afd44184_fk_auth_user_id" FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED ``` `SELECT * FROM information_schema.sequences WHERE sequence_name='users_userconfig_id_seq';` should return the sequence. I can't imagine how you'd get to this state without someone having directly manipulated the PostgreSQL database to drop the sequence. You can try to restore it manually, but I'd suggest first determining how it happened, as there may be other issues lurking. Please post to our [mailing list](https://groups.google.com/forum/#!forum/netbox-discuss) if you require any further assistance.
Author
Owner

@exiz01 commented on GitHub (Sep 30, 2020):

Ok thanks for the help but, why would this happen in the first place? I did nothing besides installing netbox as is supposed to be installed, I would say this may happen to anyone else.

@exiz01 commented on GitHub (Sep 30, 2020): Ok thanks for the help but, why would this happen in the first place? I did nothing besides installing netbox as is supposed to be installed, I would say this may happen to anyone else.
Author
Owner

@jeremystretch commented on GitHub (Sep 30, 2020):

Without having seen exactly what you did, it's impossible to say. It's not something that's likely to happen, nor has it ever before been reported.

@jeremystretch commented on GitHub (Sep 30, 2020): Without having seen exactly what you did, it's impossible to say. It's not something that's likely to happen, nor has it ever before been reported.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4130