ASKBOT / askbot-devel

Askbot is a Django/Python Q&A forum. **Contributors README**: https://github.com/ASKBOT/askbot-devel#how-to-contribute. Commercial hosting of Askbot and support are available at https://askbot.com
Other
1.56k stars 626 forks source link

LDAP_CREATE_USER_FUNCTION not working in 0.11.x? #905

Closed brunobastosg closed 2 years ago

brunobastosg commented 2 years ago

I use a custom create user function in my existing Askbot 0.10.2 instance and it's working fine. There is a custom_user_creation.py file in the root of the Django project. In my settings.py, there is the following entry: LDAP_CREATE_USER_FUNCTION = 'custom_user_creation.ldap_create_user_default'. Everything works great!

However, I'm trying to upgrade to Askbot 0.11.x to use Python 3 and a newer Django version. Whenever I ran python my_site/manage.py migrate, the following error occurs:

Traceback (most recent call last):
  File "my_site/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 361, in execute
    self.check()
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 387, in check
    all_issues = self._run_checks(
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 65, in _run_checks
    issues.extend(super()._run_checks(**kwargs))
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/my_app/.venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/my_app/.venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 403, in check
    for pattern in self.url_patterns:
  File "/my_app/.venv/lib/python3.8/site-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/my_app/.venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 588, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/my_app/.venv/lib/python3.8/site-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/my_app/.venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 581, in urlconf_module
    return import_module(self.urlconf_name)
  File "/opt/programas/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/my_app/my_site/my_app/urls.py", line 12, in <module>
    import askbot.urls
  File "/my_app/.venv/lib/python3.8/site-packages/askbot-0.11.3-py3.8.egg/askbot/urls.py", line 19, in <module>
    import askbot.deps.django_authopenid.urls
  File "/my_app/.venv/lib/python3.8/site-packages/askbot-0.11.3-py3.8.egg/askbot/deps/django_authopenid/urls.py", line 13, in <module>
    from askbot.deps.django_authopenid import views as OpenidViews
  File "/my_app/.venv/lib/python3.8/site-packages/askbot-0.11.3-py3.8.egg/askbot/deps/django_authopenid/views.py", line 59, in <module>
    from askbot.deps.django_authopenid.ldap_auth import ldap_create_user
  File "/my_app/.venv/lib/python3.8/site-packages/askbot-0.11.3-py3.8.egg/askbot/deps/django_authopenid/ldap_auth.py", line 207, in <module>
    ldap_create_user = load_module(LDAP_CREATE_FUNC_PATH)
  File "/my_app/.venv/lib/python3.8/site-packages/askbot-0.11.3-py3.8.egg/askbot/utils/loading.py", line 12, in load_module
    return importlib.import_module(mod_path)
  File "/opt/programs/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'custom_user_creation'

I have tried moving this file to several folders, but the error persists.

Does anybody have any idea what could be the issue? Is this a bug or am I doing something wrong?

Thanks in advance!

brunobastosg commented 2 years ago

I believe the problem is in /askbot/deps/django_authopenid/ldap_auth.py:

LDAP_AUTH_FUNC_PATH = getattr(django_settings, 'LDAP_AUTHENTICATE_FUNCTION', None)
if LDAP_AUTH_FUNC_PATH:
    ldap_authenticate = load_module(LDAP_AUTH_FUNC_PATH)
else:
    ldap_authenticate = ldap_authenticate_default

LDAP_CREATE_FUNC_PATH = getattr(django_settings, 'LDAP_CREATE_USER_FUNCTION', None)
if LDAP_CREATE_FUNC_PATH:
    ldap_create_user = load_module(LDAP_CREATE_FUNC_PATH)
else:
    ldap_create_user = ldap_create_user_default

Instead of load_module, it should call load_function.

I'll submit a PR.