Invalid import in cache_lock.py – portalocker.exceptions does not exist
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.
Here is the full exception
CertificateCredential.get_token failed: Authentication failed: module 'portalocker' has no attribute 'exceptions'
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?
Further suggestions.
The issue WOULD happen if BOTH of the following conditions were met:
- Customer's code explicitly uses the
cache_lock.py - Customer's environment does NOT have
portalockerinstalled.
HOWEVER, neither of the two conditions should occur.
#1is not the correct way to use MSAL EX. Please follow our samples.#2i.e. the absence ofportalockershall not be an issue if the caller did#1right, becauseportalockeris no longer required since MSAL EX 1.3.x. If customer fixes#1, they won't need to fiddle withportalocker.