Skip to content

Commit db889c7

Browse files
committed
Remind developers about http_cache's unstable format
1 parent 5a1a0ff commit db889c7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

msal/application.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,13 @@ def __init__(
495495
496496
If your app is a command-line app (CLI),
497497
you would want to persist your http_cache across different CLI runs.
498+
The persisted file's format may change due to, but not limited to,
499+
`unstable protocol <https://docs.python.org/3/library/pickle.html#data-stream-format>`_,
500+
so your implementation shall tolerate unexpected loading errors.
498501
The following recipe shows a way to do so::
499502
500503
# Just add the following lines at the beginning of your CLI script
501-
import sys, atexit, pickle
504+
import sys, atexit, pickle, logging
502505
http_cache_filename = sys.argv[0] + ".http_cache"
503506
try:
504507
with open(http_cache_filename, "rb") as f:
@@ -509,6 +512,9 @@ def __init__(
509512
AttributeError, # Cache created by a different version of MSAL
510513
):
511514
persisted_http_cache = {} # Recover by starting afresh
515+
except: # Unexpected exceptions
516+
logging.exception("You may want to debug this")
517+
persisted_http_cache = {} # Recover by starting afresh
512518
atexit.register(lambda: pickle.dump(
513519
# When exit, flush it back to the file.
514520
# It may occasionally overwrite another process's concurrent write,
@@ -2012,12 +2018,12 @@ def __init__(
20122018
This parameter defaults to None, which means MSAL will not utilize a broker.
20132019
20142020
New in MSAL Python 1.31.0.
2015-
2021+
20162022
:param boolean enable_broker_on_linux:
20172023
This setting is only effective if your app is running on Linux, including WSL.
20182024
This parameter defaults to None, which means MSAL will not utilize a broker.
20192025
2020-
New in MSAL Python 1.33.0.
2026+
New in MSAL Python 1.33.0.
20212027
20222028
:param boolean enable_broker_on_wsl:
20232029
This setting is only effective if your app is running on WSL.

tox.ini

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ commands =
1717
pip list
1818
{posargs:pytest --color=yes}
1919

20+
[testenv:docs]
21+
deps =
22+
-r docs/requirements.txt
23+
commands =
24+
sphinx-build docs docs/_build
25+
2026
[testenv:azcli]
2127
deps =
2228
azure-cli

0 commit comments

Comments
 (0)