Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'soft_unicode' from 'markupsafe' in Release 1.38.0 #3661

Closed
SamkeetJainMensa opened this issue Feb 18, 2022 · 44 comments
Labels

Comments

@SamkeetJainMensa
Copy link

SamkeetJainMensa commented Feb 18, 2022

I'm building the sam project on github action and since the upgrade of sam-cli to 1.38.0, i'm getting following error when i build project

Python version: 3.10.2 & 3.8.12 (Tried both versions)
Pip version: pip-22.0.3
Sam cli version: 1.38.0

Command: sam build --template ${SAM_TEMPLATE} --use-container

Trace:

Traceback (most recent call last):
  File "/home/runner/work/_temp/setup-sam-43osIE/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 8[29](https://github.com/mensabrands/dip-app/runs/5243143255?check_suite_focus=true#step:5:29), in __call__
    return self.main(*args, **kwargs)
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/telemetry/metric.py", line 166, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/telemetry/metric.py", line 124, in wrapped
    return_value = func(*args, **kwargs)
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/utils/version_checker.py", line 41, in wrapped
    actual_result = func(*args, **kwargs)
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/cli/main.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/commands/build/command.py", line 174, in cli
    do_cli(
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/commands/build/command.py", line 220, in do_cli
    from samcli.commands.build.build_context import BuildContext
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/commands/build/build_context.py", line 13, in <module>
    from samcli.lib.providers.sam_api_provider import SamApiProvider
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/providers/sam_api_provider.py", line 6, in <module>
    from samcli.lib.providers.api_collector import ApiCollector
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/providers/api_collector.py", line 10, in <module>
    from samcli.local.apigw.local_apigw_service import Route
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/local/apigw/local_apigw_service.py", line 11, in <module>
    from flask import Flask, request
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/flask/__init__.py", line 14, in <module>
    from jinja2 import escape
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/jinja2/__init__.py", line 12, in <module>
    from .environment import Environment
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/jinja2/environment.py", line 25, in <module>
    from .defaults import BLOCK_END_STRING
  File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/jinja2/defaults.py", line 3, in <module>
    from .filters import FILTERS as DEFAULT_FILTERS  # noqa: F[40](https://github.com/mensabrands/dip-app/runs/5243143255?check_suite_focus=true#step:5:40)1
  File "/home/runner/work/_temp/setup-sam-[43](https://github.com/mensabrands/dip-app/runs/5243143255?check_suite_focus=true#step:5:43)osIE/.venv/lib/python3.10/site-packages/jinja2/filters.py", line 13, in <module>
    from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/markupsafe/__init__.py)

I revert sam-cli version to 1.37.0 and it worked perfectly.

@SamkeetJainMensa
Copy link
Author

Looks the issue is due to upgrade in MarkupSafe:2.1.0 where they have removed soft_unicode.
Release note: https://markupsafe.palletsprojects.com/en/2.1.x/changes/#version-2-1-0

sam-cli:1.37.0 is downloading MarkupSafe:2.0.1 and sam-cli:1.38.0 is downloading MarkupSafe:2.1.0.

@echaoeoen
Copy link

echaoeoen commented Feb 18, 2022

I tried to change the version of sam to 1.29.0 in github actions using this action, seemslike it still download the newest version of Markupsafe
Screen Shot 2022-02-18 at 14 02 03

@olmolod
Copy link

olmolod commented Feb 18, 2022

same here - seems MarkUoSafe was updated and there is no soft_unicode there any more. How to solve this?

`- step: &build_stage
            name: build
            image: python:3.9
            script:
                - apt-get update && apt-get install -y python3-pip zip 
                - pip install -U awscli
                - aws --version
                - aws configure set default.region $AWS_DEFAULT_REGION
                - aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID_STAGE"
                - aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY_STAGE"
                - pip install --user --upgrade aws-sam-cli
                - ln -s /root/.local/bin/sam /usr/bin/sam
                - sam --version
                - sam build`

pip install --user --upgrade aws-sam-cli - gets last version on Jijnja

Collecting Jinja2<4.0.0,>=2.7
Using cached Jinja2-3.0.3-py3-none-any.whl (133 kB)

yesterday was
Collecting Jinja2<4.0.0,>=2.7
Using cached Jinja2-2.11.3-py2.py3-none-any.whl (125 kB)

@sthadapradit
Copy link

@SamkeetJainMensa, thanks lot, it's working with 1.37.0, I did this change in gitaction

  - uses: aws-actions/setup-sam@v1
    with:
      version: 1.37.0

@olmolod
Copy link

olmolod commented Feb 18, 2022

@sthadapradit this I did, but it is temproary solution - any idea how to come back to
pip install --user --upgrade aws-sam-cli
insted
pip install --user aws-sam-cli ==1.37.0

@BCarley
Copy link

BCarley commented Feb 18, 2022

Looks like a breaking change in markupsafe and jinja not specifying an upper version bound pallets/markupsafe#286

@Yop-La
Copy link

Yop-La commented Feb 18, 2022

I'm getting the same error with "SAM CLI, version 1.37.0". I have not upgraded.

@MurphyAdam
Copy link

I had this issue with Django using Jinja2. Jinja2 imports soft_unicode from the package causing it to break.

@Yop-La
Copy link

Yop-La commented Feb 18, 2022

Downgrading markupsafe to 2.0.1 fixes the issue on my side.
pip install markupsafe==2.0.1

@davidism
Copy link

aws-sam-cli is using an unsupported version of Jinja, they need to update to the latest version. Additionally, they need to read https://hynek.me/articles/semver-will-not-save-you/, then use a tool like pip-tools to pin their dependencies to control when their users get updates. Be sure to run tests with deprecation warnings treated as errors so that these types of changes show up early.

konstan added a commit to nuvla/kafka-notify that referenced this issue Feb 18, 2022
konstan added a commit to nuvla/kafka-notify that referenced this issue Feb 18, 2022
* fix issue
* test and build in CI
* minor
* typo
* fix for aws/aws-sam-cli#3661
* exec permission for container-release.sh
* multi-arch docker image build required
@jfuss
Copy link
Contributor

jfuss commented Feb 18, 2022

Looking into this. Though this is why we do not recommend using pip to install and instead use our installers.

@davidism We are stuck in a place that if we pin, customers get upset that they can install with all their other tools (in a single interpreter instead of isolating). If we don't pin (everything), we run into this things. So it's a who do we block/make angry situation. Would be great if python (pip) actually solved this instead of each tool having to battle users on how to install or providing ways tools can vend safely through pip.

@codybc
Copy link

codybc commented Feb 18, 2022

Just ran into this issue installing with aws-actions/setup-sam@v1

easy fix if anyone else sees this though, setup-sam allows you to set version

- uses: aws-actions/setup-sam@v1
   with:
     version: 1.37.0

@mndeveci
Copy link
Contributor

Thanks for reporting this issue. SAM CLI v1.38.1 is released which contains the fix for it. As @jfuss mentioned, we would highly recommend using our installers (NativeInstaller for Linux, brew for MacOS and MSI for Windows).

Resolving the issue.

cdoyle-temple added a commit to tulibraries/ansible-role-server-bootstrap that referenced this issue Jul 14, 2022
@Amanrajdas01
Copy link

same here - seems MarkUoSafe was updated and there is no soft_unicode there any more. How to solve this?

`- step: &build_stage
            name: build
            image: python:3.9
            script:
                - apt-get update && apt-get install -y python3-pip zip 
                - pip install -U awscli
                - aws --version
                - aws configure set default.region $AWS_DEFAULT_REGION
                - aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID_STAGE"
                - aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY_STAGE"
                - pip install --user --upgrade aws-sam-cli
                - ln -s /root/.local/bin/sam /usr/bin/sam
                - sam --version
                - sam build`

pip install --user --upgrade aws-sam-cli - gets last version on Jijnja

Collecting Jinja2<4.0.0,>=2.7 Using cached Jinja2-3.0.3-py3-none-any.whl (133 kB)

yesterday was Collecting Jinja2<4.0.0,>=2.7 Using cached Jinja2-2.11.3-py2.py3-none-any.whl (125 kB)

thankyou, it works

tetsuya-ki added a commit to tetsuya-ki/discord-reminderbot that referenced this issue Jul 31, 2022
下記と同じようにImportErrorが発生したため
aws/aws-sam-cli#3661
AlexMikhalev added a commit to AlexMikhalev/automation-api-examples that referenced this issue Aug 3, 2022
kazuyukitanimura pushed a commit to kazuyukitanimura/spark that referenced this issue Aug 10, 2022
### What changes were proposed in this pull request?

This PR proposes to pin the Python package `markupsafe` to 2.0.1 to fix the CI failure as below.

```
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/markupsafe/__init__.py)
```

Since `markupsafe==2.1.0` has removed `soft_unicode`, `from markupsafe import soft_unicode` no longer working properly.

See aws/aws-sam-cli#3661 for more detail.

### Why are the changes needed?

To fix the CI failure on branch-3.2

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

The existing tests are should be passed

Closes apache#35602 from itholic/SPARK-38279.

Authored-by: itholic <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
fushar pushed a commit to ioi/cms that referenced this issue Aug 28, 2022
fushar pushed a commit to ioi/cms that referenced this issue Aug 30, 2022
@SamarShabanCS
Copy link

Downgrading markupsafe to 2.0.1 fixes the issue on my side. pip install markupsafe==2.0.1

Thanks a lot.
It solved the problem

HuJK added a commit to HuJK/Code-Server-Hub that referenced this issue Oct 4, 2022
Fix issue aws/aws-sam-cli#3661
Downgrade markupsafe to 2.0.1
Craeckie added a commit to Craeckie/matrix-registration that referenced this issue Nov 4, 2022
crystaldust added a commit to crystaldust/airflow-jobs that referenced this issue Mar 20, 2023
Add the constraint of markupsafe version to 2.0.1, according to the ref:
aws/aws-sam-cli#3661 (comment)
crystaldust added a commit to crystaldust/airflow-jobs that referenced this issue Mar 20, 2023
Add the constraint of markupsafe version to 2.0.1, according to the ref:
aws/aws-sam-cli#3661 (comment)

Add a snapshot of version 2.2.3's Dockerfile
crystaldust added a commit to oss-know/airflow-jobs that referenced this issue Mar 20, 2023
Add the constraint of markupsafe version to 2.0.1, according to the ref:
aws/aws-sam-cli#3661 (comment)

Add a snapshot of version 2.2.3's Dockerfile
baztian added a commit to baztian/ansible-aws that referenced this issue Mar 24, 2023
@fpena06
Copy link

fpena06 commented Jun 23, 2023

Downgrading markupsafe to 2.0.1 fixes the issue on my side. pip install markupsafe==2.0.1

thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests