microsoft-authentication-extensions-for-python icon indicating copy to clipboard operation
microsoft-authentication-extensions-for-python copied to clipboard

Invalid import in cache_lock.py – portalocker.exceptions does not exist

Open daga05 opened this issue 7 months ago • 3 comments

We're encountering a runtime failure using msal-extensions==1.3.1 due to an invalid reference to portalocker.exceptions in cache_lock.py:

LockError = portalocker.exceptions.LockException

This causes authentication logic to break with:

AttributeError: module 'portalocker' has no attribute 'exceptions'

The current version of the portalocker package (e.g., 2.10.1) no longer exposes an exceptions module or attribute at the top level.

Suggested Fix:

Change the reference to:

import portalocker LockError = portalocker.LockException

Confirmed Environment:

msal-extensions: 1.3.1 portalocker: 2.10.1 Python 3.11 Runtime: Azure App Service (Linux)

Please let us know if a fix can be included in the next release. We're happy to help validate or contribute a PR.

daga05 avatar May 29 '25 21:05 daga05

Here is the full exception

CertificateCredential.get_token failed: Authentication failed: module 'portalocker' has no attribute 'exceptions'

junior-juarez-MSFT avatar May 29 '25 21:05 junior-juarez-MSFT

But I am not able to reproduce the issue.

pip list
Package        Version
-------------- -------
pip            25.0.1
portalocker    2.10.1
security_state 0.0.0
setuptools     78.1.0
wheel          0.45.1
py3: commands[1]> python -c 'import portalocker; portalocker.exceptions.LockException; print("import successfully")'
import successfully

Can you share a way to reproduce it?

rayluo avatar May 29 '25 22:05 rayluo

Further suggestions.

The issue WOULD happen if BOTH of the following conditions were met:

  1. Customer's code explicitly uses the cache_lock.py
  2. Customer's environment does NOT have portalocker installed.

HOWEVER, neither of the two conditions should occur.

rayluo avatar May 29 '25 23:05 rayluo