Search code examples
python-3.xazure-cli

Error with Azure CLI : Unable to load extension 'alias: cannot import name 'soft_unicode' from 'markupsafe'


After adding alias to Azure CLI I get this error when trying to use it:

Unable to load extension 'alias: cannot import name 'soft_unicode' from 'markupsafe' (/home/anyuser/.azure/cliextensions/alias/markupsafe/__init__.py)'. Use --debug for more information. 'alias' is misspelled or not recognized by the system.

with

azure-cli                         2.51.0

core                              2.51.0
telemetry                          1.1.0

Extensions:
alias                              0.5.2

Solution

  • After learning that a corresponding issue had no resolution yet, related issues where pointing to a compatibility problem with version 2.1.x of markupsafe library, I created and applied this script as a quick fix to patch version 2.0.1 on the extension:

    #!/bin/bash
    set -e
    extpath=`az extension list --query "[?name=='alias'].path" -o tsv`
    version=2.0.1
    wget https://github.com/pallets/markupsafe/archive/refs/tags/$version.tar.gz -O ~/markupsafe-$version.tar.gz
    tar xvf ~/markupsafe-$version.tar.gz -C ~
    cp ~/markupsafe-$version/src/markupsafe/* $extpath/markupsafe