User gets error after few seconds because of LDAP error

Open
#10,756 10 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
18/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
django, python

Research direction

The crash is in users/permissions.py at check_user_permission, which calls user.has_perm, and it fails inside django_auth_ldap when search_s receives a None base DN. Start by checking how the LDAP group search settings are read in the InvenTree settings and where the group base is passed to django_auth_ldap. Reproducing it needs an LDAP server, and the issue does not say which group setting is empty, so confirm that first. Done means a missing LDAP group setting no longer produces a TypeError on each request.

Written by the indexing model from the issue text.

Description

bug setup
Please verify that this bug has NOT been raised before.
  • I checked and didn't find a similar issue
Describe the bug*

When a new user logs in via LDAP, and I assign the correct group, then, even after relogin (and browser cache clearance etc). I get the following error:

Image
Steps to Reproduce
  1. New user logs in using LDAP
  2. Assign correct group
  3. Relogin and clear browser
  4. go to parts overview and wait a few secondss
  5. Parts disappear and error appears.
Expected behaviour

No errors

Deployment Method

Docker

Version Information

InvenTree-Version: 1.1.1
Django Version: 4.2.25
Commit Hash: d3a58ea
Commit Date: 2025-11-03
Commit Branch: null
Database: django.db.backends.postgresql
Debug-Mode: True
Deployed using Docker: True
Platform: Linux-6.1.0-40-amd64-x86_64-with-glibc2.41
Installer: DOC
Active plugins: [{"name":"InvenTreeBarcode","slug":"inventreebarcode","version":"2.1.0"},{"name":"BOM Exporter","slug":"bom-exporter","version":"1.1.0"},{"name":"InvenTree Exporter","slug":"inventree-exporter","version":"1.0.0"},{"name":"Part Parameter Exporter","slug":"parameter-exporter","version":"1.0.0"},{"name":"InvenTreeEmailNotifications","slug":"inventree-email-notification","version":"1.0.0"},{"name":"InvenTreeUINotifications","slug":"inventree-ui-notification","version":"1.0.0"},{"name":"InvenTreeCurrencyExchange","slug":"inventreecurrencyexchange","version":"1.0.0"},{"name":"InvenTreeMachines","slug":"inventree-machines","version":"1.0.0"},{"name":"InvenTreeLabel","slug":"inventreelabel","version":"1.1.0"},{"name":"InvenTreeLabelMachine","slug":"inventreelabelmachine","version":"1.0.0"},{"name":"Altium BOM Importer","slug":"altium-bom-importer","version":"0.2.0"},{"name":"Altium Connector","slug":"altium-connector","version":"0.3.0"},{"name":"Custom BOM Exporter","slug":"custom_bom_exporter","version":"0.2.2"},{"name":"IPNGenerator","slug":"ipngen","version":"0.2"},{"name":"SolidWorks BOM Importer","slug":"solidworks-bom-importer","version":"0.2.0"},{"name":"Tree View","slug":"tree-view","version":"0.1.1"}]

Try to reproduce on the demo site

I did not try to reproduce

Is the bug reproducible on the demo site?

Not reproducible

Relevant log output

Traceback (most recent call last):

File "/root/.local/lib/python3.11/site-packages/rest_framework/views.py", line 512, in dispatch

response = handler(request, *args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/rest_framework/views.py", line 526, in options

data = self.metadata_class().determine_metadata(request, self)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/inventree/src/backend/InvenTree/InvenTree/metadata.py", line 130, in determine_metadata

result = check_user_permission(user, self.model, permission) or (

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/inventree/src/backend/InvenTree/users/permissions.py", line 165, in check_user_permission

result = user.has_perm(permission_name)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/contrib/auth/models.py", line 311, in has_perm

return _user_has_perm(self, perm, obj)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django/contrib/auth/models.py", line 220, in _user_has_perm

if backend.has_perm(user, perm, obj):

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django_auth_ldap/backend.py", line 192, in has_perm

return perm in self.get_all_permissions(user, obj)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django_auth_ldap/backend.py", line 202, in get_all_permissions

return self.get_group_permissions(user, obj)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django_auth_ldap/backend.py", line 209, in get_group_permissions

permissions = user.ldap_user.get_group_permissions()

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django_auth_ldap/backend.py", line 405, in get_group_permissions

self._load_group_permissions()

File "/root/.local/lib/python3.11/site-packages/django_auth_ldap/backend.py", line 841, in _load_group_permissions

group_names = self._get_groups().get_group_names()

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django_auth_ldap/backend.py", line 949, in get_group_names

group_infos = self._get_group_infos()

^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django_auth_ldap/backend.py", line 996, in _get_group_infos

self._group_infos = self._group_type.user_groups(

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django_auth_ldap/config.py", line 536, in user_groups

return search.execute(ldap_user.connection)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/django_auth_ldap/config.py", line 204, in execute

results = connection.search_s(

^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/ldap/ldapobject.py", line 631, in search_s

return self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout=self.timeout)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/ldap/ldapobject.py", line 624, in search_ext_s

msgid = self.search_ext(base,scope,filterstr,attrlist,attrsonly,serverctrls,clientctrls,timeout,sizelimit)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/ldap/ldapobject.py", line 614, in search_ext

return self._ldap_call(

^^^^^^^^^^^^^^^^

File "/root/.local/lib/python3.11/site-packages/ldap/ldapobject.py", line 128, in _ldap_call

result = func(*args,**kwargs)

^^^^^^^^^^^^^^^^^^^^

TypeError: search_ext() argument 1 must be str, not None
Dominant language
Python
Stars
7.7k
Forks
1.6k
Avg merge
21h 45m
Merged PRs (30d)
204

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from inventree/InvenTree

All issues in inventree/InvenTree

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.