Skip to content

AttributeError: 'module' object has no attribute '_trace_level' #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
misery opened this issue Jun 22, 2018 · 5 comments · Fixed by #234
Closed

AttributeError: 'module' object has no attribute '_trace_level' #226

misery opened this issue Jun 22, 2018 · 5 comments · Fixed by #234

Comments

@misery
Copy link

misery commented Jun 22, 2018

Issue description:
After an upgrade from 3.0.0 to 3.1.0 I cannot login into my review board as the ldap module throws an error. After an downgrade everything works fine.

Steps to reproduce:

[...]
  File "/opt/reviewboard/dist/lib/python2.7/site-packages/reviewboard/accounts/backends.py", line 1008, in authenticate
    for uri, connection in self.get_ldap_connections(userdomain):

  File "/opt/reviewboard/dist/lib/python2.7/site-packages/reviewboard/accounts/backends.py", line 935, in get_ldap_connections
    connection = ldap.initialize(ldap_uri)

  File "/opt/reviewboard/dist/lib/python2.7/site-packages/ldap/functions.py", line 85, in initialize
    return LDAPObject(uri,trace_level,trace_file,trace_stack_limit,bytes_mode)

  File "/opt/reviewboard/dist/lib/python2.7/site-packages/ldap/ldapobject.py", line 99, in __init__
    self._trace_level = trace_level or ldap._trace_level

AttributeError: 'module' object has no attribute '_trace_level'

Operating system: Linux
Python version: 2.7.14
python-ldap version: 3.1.0 and 3.0.0

@Xophmeister
Copy link

I am able to replicate this -- and came to post an issue -- but only when running Python with optimisations enabled (i.e., python -O or python -OO).

Steps to reproduce:

In test.py:

import ldap
ldap.initialize("ldap://my.ldap.host")

Then at the command line:

$ python -O test.py
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    server = ldap.initialize("ldap://my.ldap.host")
  File "/Users/ch12/Projects/play/python/ldap/.venv/lib/python3.6/site-packages/ldap/functions.py", line 85, in initialize
    return LDAPObject(uri,trace_level,trace_file,trace_stack_limit,bytes_mode)
  File "/Users/ch12/Projects/play/python/ldap/.venv/lib/python3.6/site-packages/ldap/ldapobject.py", line 99, in __init__
    self._trace_level = trace_level or ldap._trace_level
AttributeError: module 'ldap' has no attribute '_trace_level'

This is with Python 3.6.5 on macOS 10.11.6, with python-ldap 3.1.0

encukou added a commit to encukou/python-ldap that referenced this issue Jul 30, 2018
All use of these attributes *should* be guarded by `if __debug__`.
However, that's not always the case. Providing different API based
on __debug__ is unnecessarily fragile.

This is intended as a quick fix for a maintenance release.

Fixes: python-ldap#226
encukou added a commit to encukou/python-ldap that referenced this issue Jul 30, 2018
All use of these attributes *should* be guarded by `if __debug__`.
However, that's not always the case. Providing different API based
on __debug__ is unnecessarily fragile.

This is intended as a quick fix for a maintenance release.

Fixes: python-ldap#226
encukou added a commit to encukou/python-ldap that referenced this issue Jul 30, 2018
All use of these attributes *should* be guarded by `if __debug__`.
However, that's not always the case. Providing different API based
on __debug__ is unnecessarily fragile.

This is intended as a quick fix for a maintenance release.

Fixes: python-ldap#226
nijel added a commit to WeblateOrg/weblate that referenced this issue Oct 11, 2018
See python-ldap/python-ldap#226

Signed-off-by: Michal Čihař <michal@cihar.com>
nijel added a commit to WeblateOrg/weblate that referenced this issue Oct 20, 2018
See python-ldap/python-ldap#226

Signed-off-by: Michal Čihař <michal@cihar.com>
@chiragsoni2401
Copy link

I am facing the same issue on windows machine with python v3.7.2 and python-ldap 3.1.0
I tried to downgrade to python-ldap to 2.5.2 but even not able to install it. Getting following error.

python_ldap-2.5.2-cp27-cp27m-win_amd64.whl is not a supported wheel on this plat
form.

@encukou
Copy link
Member

encukou commented Feb 4, 2019

Pull request #234 should fix the problem. I'd be grateful if you could check if the change fixes the issue.

@Battlesheepu
Copy link

Battlesheepu commented Mar 7, 2019

I find it a bit scary that, once __debug __ is off (which should be in prod) and this very argument is not passed, the app simply fails when initializing a connection.

As a quick workaround I recommend passing pretty much anything as trace_level when initializing connection - as long as the value does not evaluate to False. '0' would be a good example - although this will crash under __debug __.

For prod:

connection = ldap.initialize(ldap_uri, trace_level='0')

For debug:

connection = ldap.initialize(ldap_uri)

@encukou
Copy link
Member

encukou commented Mar 8, 2019

Again: Pull request #234 should fix the problem.
I'd be grateful for a review, so the change can get out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants