Skip to content

[BUG] After AzureCli@2 uses azure-cli==2.70.0 instead of azure-cli==2.65.0, importing azure.ai.ml module has ImportError: cannot import name '_T' from 'marshmallow.fields' #31020

@winnieshen96

Description

@winnieshen96

Describe the bug

When using AzureCli@2 task in Azure DevOps, if I run a python script, in which I import modules from azure.ai.ml, it will have the error below.

It was working before when AzureCLI@2 has the azure-cli version as 2.65.0. I ran the same pipeline without any changes last week and it worked. But this week, when the azure-cli version is 2.70.0, this bug occurs.

Related command

  • task: AzureCLI@2
    inputs:
    azureSubscription: ${{ parameters.WRKSP_SVC_CONN }}
    scriptType: bash
    scriptLocation: inlineScript
    workingDirectory: $(Build.SourcesDirectory)
    addSpnToEnvironment: true
    inlineScript: |
    python -m sample

Inside the sample.py file:
from azure.ai.ml import MLClient, Output, command, dsl

Errors

File "/usr/local/lib/python3.11/site-packages/azure/ai/ml/entities/_assets/__init__.py", line 9, in <module>
    from ._artifacts.code import Code
  File "/usr/local/lib/python3.11/site-packages/azure/ai/ml/entities/_assets/_artifacts/code.py", line 10, in <module>
    from azure.ai.ml._schema import CodeAssetSchema
  File "/usr/local/lib/python3.11/site-packages/azure/ai/ml/_schema/__init__.py", line 7, in <module>
    from ._sweep import SweepJobSchema
  File "/usr/local/lib/python3.11/site-packages/azure/ai/ml/_schema/_sweep/__init__.py", line 7, in <module>
    from .sweep_job import SweepJobSchema
  File "/usr/local/lib/python3.11/site-packages/azure/ai/ml/_schema/_sweep/sweep_job.py", line 7, in <module>
    from azure.ai.ml._schema._sweep.parameterized_sweep import ParameterizedSweepSchema
  File "/usr/local/lib/python3.11/site-packages/azure/ai/ml/_schema/_sweep/parameterized_sweep.py", line 7, in <module>
    from azure.ai.ml._schema.core.fields import ExperimentalField, NestedField, PathAwareSchema
  File "/usr/local/lib/python3.11/site-packages/azure/ai/ml/_schema/core/fields.py", line 19, in <module>
    from marshmallow.fields import _T, Field, Nested
ImportError: cannot import name '_T' from 'marshmallow.fields' (/usr/local/lib/python3.11/site-packages/marshmallow/fields.py)

Issue script & Debug output

Not applicable

Expected behavior

The error should not happen, and the import should happen successfully.

Environment Summary

azure-cli 2.70.0

core 2.70.0
telemetry 1.1.0

Dependencies:
msal 1.31.2b1
azure-mgmt-resource 23.1.1

Python location '/usr/local/bin/python3.11'
Config directory '/home/AzDevOps_azpcontainer/.azure'
Extensions directory '/home/AzDevOps_azpcontainer/.azure/cliextensions'

Python (Linux) 3.11.11 (main, Feb 25 2025, 05:21:12) [GCC 12.2.0]

Additional context

For running this Azure Pipeline, I use custom image from Azure Container Registry, and in that image, I installed azure-ai-ml==1.25.0

I have no issue running imports from azure-ai-ml==1.25.0 elsewhere. This issue only happens when I run this python file in the AzureCli@2 task. And I have to use AzureCli@2 because it can addSpnToEnvironment.

I have found a hotfix solution: I have to manually add this to every single AzureCli@2 task if I run a python file with azure.ai.ml imports in it:
python -m pip install marshmallow==3.23.2
It resolves the error, but this is not ideal at all. Please address this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Machine Learningaz mlService AttentionThis issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions