I have a Django app that I am deploying as a Azure linux web app. It has been running fine for months but now on startup after deployment via AzDO CI/CD pipeline it errors with
from collections import Sequence
at line 10 when loading pathlib.py from the MS version in the docker container.
The official version of pathlib.py (https://github.com/python/cpython/blob/3.12/Lib/pathlib.py) reads
from _collections_abc import Sequence
See docs at https://docs.python.org/3/library/pathlib.html
This is a known problem and is resolved by moving from the MS version to the later official version. The issue is that this problem is in the MS distro and not in my code or even the version of the library that gets installed with pip. Even if you change it, any deployment over-writes the correct version with the version in the MS distro.
The app works fine locally with the official pathlib.py and previously worked OK on Azure. It looks like a regression error with the library being used. I have tried editing the Azure version of pathlib.py but it gets over-written on every [container] restart or redeployment.
How can I change the version of pathlib.py being used by Azure or otherwise work-around this please?
Make sure you are using the correct version of
pathlib.pyin your project directory and load it in your system.You can create a docker image and deploy your Dockerized Web App in Azure.
During the initialization phase of your application, such as in Django's
settings.pyfile, you can modify the behavior ofpathlibafter importing it by adjusting theSequenceclass to use the correct one from_collections_abc. This approach might require making alterations to the internal functionality ofpathlib, commonly referred to as monkey-patching, although it's not an ideal solution, it could function as a temporary fix.My Folder Structure:-
pathlib.py:-My settings.py:-
My Azure DevOps yaml pipeline:-
Output:-