Azure-Samples / ms-identity-python-webapp

A Python web application calling Microsoft graph that is secured using the Microsoft identity platform
MIT License
298 stars 143 forks source link

running with Python 2 is broken due to new release of cachelib==0.1.1 #52

Closed eprigorodov closed 4 years ago

eprigorodov commented 4 years ago

Following the README guide fails on the "Step 4. Run the sample" with the following traceback:

  File "/home/user/ms-identity-python-webapp-master/app.py", line 11, in <module>
    Session(app)
  File "/home/user/ms-identity-python-webapp-master/venv/local/lib/python2.7/site-packages/flask_session/__init__.py", line 54, in __init__
    self.init_app(app)
  File "/home/user/ms-identity-python-webapp-master/venv/local/lib/python2.7/site-packages/flask_session/__init__.py", line 61, in init_app
    app.session_interface = self._get_interface(app)
  File "/home/user/ms-identity-python-webapp-master/venv/local/lib/python2.7/site-packages/flask_session/__init__.py", line 93, in _get_interface
    config['SESSION_USE_SIGNER'], config['SESSION_PERMANENT'])
  File "/home/user/ms-identity-python-webapp-master/venv/local/lib/python2.7/site-packages/flask_session/sessions.py", line 313, in __init__
    self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
  File "/home/user/ms-identity-python-webapp-master/venv/local/lib/python2.7/site-packages/cachelib/file.py", line 54, in __init__
    self._update_count(value=len(self._list_dir()))
  File "/home/user/ms-identity-python-webapp-master/venv/local/lib/python2.7/site-packages/cachelib/file.py", line 69, in _update_count
    self.set(self._fs_count_file, new_count, mgmt_element=True)
  File "/home/user/ms-identity-python-webapp-master/venv/local/lib/python2.7/site-packages/cachelib/file.py", line 158, in set
    os.replace(tmp, filename)
AttributeError: 'module' object has no attribute 'replace'

That happens due the last release of cachelib==0.1.1, a dependency package pulled by flask-sessions~=0.3.2, this particular commit: fa376861b7e8364531e0f673ee97a8278897c3e0. os.replace() is only available starting from Python 3.3.

The quick working fix is pinning down the version of cachelib in the requirements.txt:

Flask>=1,<2
werkzeug>=1,<2
cachelib==0.1
flask-session~=0.3.2
requests>=2,<3
msal>=0.6.1,<2
rayluo commented 4 years ago

Thanks for bringing this to our attention, Evgeny! We created an issue to the upstream cachlib. Let's see how that goes. Either they fix it there, and we do not need to change anything in our sample; or we will somehow document your workaround. But we do not plan to pin their older version here.

Meanwhile, you can use the workaround you discovered above.

eprigorodov commented 4 years ago

From the cachelib issue it seems like maintainers just have dropped support of Python 2 without declaring that. One can expect this to happen more and more in all dependencies that pull unpinned packages. Eventually, support of Python 2 in this package will also be broken completely. Maybe the document update that you mention should just reflect that.