Skip to content

Commit 448689d

Browse files
authored
fix: pop _source and yaml_str (Azure#29335)
1 parent e1cd0f1 commit 448689d

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_component/component.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -323,20 +323,25 @@ def _load(
323323
for_load=True,
324324
)
325325
new_instance = create_instance_func()
326-
init_kwargs = new_instance._load_with_schema( # pylint: disable=protected-access
327-
data,
328-
context={
329-
BASE_PATH_CONTEXT_KEY: base_path,
330-
SOURCE_PATH_CONTEXT_KEY: yaml_path,
331-
PARAMS_OVERRIDE_KEY: params_override,
332-
},
333-
unknown=INCLUDE,
334-
raise_original_exception=True,
335-
**kwargs,
326+
# specific keys must be popped before loading with schema using kwargs
327+
init_kwargs = {
328+
"yaml_str": kwargs.pop("yaml_str", None),
329+
"_source": kwargs.pop("_source", ComponentSource.YAML_COMPONENT),
330+
}
331+
init_kwargs.update(
332+
new_instance._load_with_schema( # pylint: disable=protected-access
333+
data,
334+
context={
335+
BASE_PATH_CONTEXT_KEY: base_path,
336+
SOURCE_PATH_CONTEXT_KEY: yaml_path,
337+
PARAMS_OVERRIDE_KEY: params_override,
338+
},
339+
unknown=INCLUDE,
340+
raise_original_exception=True,
341+
**kwargs,
342+
)
336343
)
337344
new_instance.__init__(
338-
yaml_str=kwargs.pop("yaml_str", None),
339-
_source=kwargs.pop("_source", ComponentSource.YAML_COMPONENT),
340345
**init_kwargs,
341346
)
342347
# Set base path separately to avoid doing this in post load, as return types of post load are not unified,

sdk/ml/azure-ai-ml/tests/component/unittests/test_component_schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import pydash
88
import pytest
99
import yaml
10-
1110
from azure.ai.ml import MLClient, load_component
1211
from azure.ai.ml._restclient.v2022_05_01.models import ComponentVersionData
1312
from azure.ai.ml._utils._arm_id_utils import PROVIDER_RESOURCE_ID_WITH_VERSION
1413
from azure.ai.ml.constants._common import BASE_PATH_CONTEXT_KEY, PARAMS_OVERRIDE_KEY, AssetTypes, LegacyAssetTypes
14+
from azure.ai.ml.constants._component import ComponentSource
1515
from azure.ai.ml.entities import CommandComponent, Component, PipelineComponent
1616
from azure.ai.ml.entities._assets import Code
1717
from azure.ai.ml.entities._component.component import COMPONENT_CODE_PLACEHOLDER, COMPONENT_PLACEHOLDER
@@ -316,6 +316,7 @@ def test_component_factory(self):
316316
context={
317317
"source_path": test_path,
318318
},
319+
_source=ComponentSource.YAML_COMPONENT,
319320
)
320321
assert recreated_component._to_dict() == component_entity._to_dict()
321322

0 commit comments

Comments
 (0)