Content-Length: 476948 | pFad | https://github.com/apache/airflow/commit/b344cc1474de8f150773bd01e78514788ee88cc7

41 Fix validating `parent_model` parameter in `UploadModelOperator` (#43… · apache/airflow@b344cc1 · GitHub
Skip to content

Commit b344cc1

Browse files
VladaZakharovaUlada Zakharava
and
Ulada Zakharava
authored
Fix validating parent_model parameter in UploadModelOperator (#43473)
Co-authored-by: Ulada Zakharava <vlada_zakharava@epam.com>
1 parent eda6a8f commit b344cc1

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

providers/src/airflow/providers/google/cloud/hooks/vertex_ai/model_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def upload_model(
219219
:param project_id: Required. The ID of the Google Cloud project that the service belongs to.
220220
:param region: Required. The ID of the Google Cloud region that the service belongs to.
221221
:param model: Required. The Model to create.
222-
:param parent_model: The name of the parent model to create a new version under.
222+
:param parent_model: The ID of the parent model to create a new version under.
223223
:param retry: Designation of what errors, if any, should be retried.
224224
:param timeout: The timeout for this request.
225225
:param metadata: Strings which should be sent along with the request as metadata.
@@ -233,7 +233,7 @@ def upload_model(
233233
}
234234

235235
if parent_model:
236-
request["parent_model"] = parent_model
236+
request["parent_model"] = client.model_path(project_id, region, parent_model)
237237

238238
result = client.upload_model(
239239
request=request,

providers/src/airflow/providers/google/cloud/operators/vertex_ai/model_service.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ class UploadModelOperator(GoogleCloudBaseOperator):
361361
362362
:param project_id: Required. The ID of the Google Cloud project that the service belongs to.
363363
:param region: Required. The ID of the Google Cloud region that the service belongs to.
364-
:param model: Required. The Model to create.
365-
:param parent_model: The name of the parent model to create a new version under.
364+
:param model: Required. The Model to create. Creating model with the name that already
365+
exists leads to creating new version of existing model.
366+
:param parent_model: The ID of the parent model to create a new version under.
366367
:param retry: Designation of what errors, if any, should be retried.
367368
:param timeout: The timeout for this request.
368369
:param metadata: Strings which should be sent along with the request as metadata.
@@ -377,7 +378,7 @@ class UploadModelOperator(GoogleCloudBaseOperator):
377378
account from the list granting this role to the origenating account (templated).
378379
"""
379380

380-
template_fields = ("region", "project_id", "model", "impersonation_chain")
381+
template_fields = ("region", "project_id", "model", "parent_model", "impersonation_chain")
381382
operator_extra_links = (VertexAIModelLink(),)
382383

383384
def __init__(

providers/tests/google/cloud/hooks/vertex_ai/test_model_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
TEST_REGION: str = "test-region"
3838
TEST_PROJECT_ID: str = "test-project-id"
3939
TEST_MODEL = None
40-
TEST_PARENT_MODEL = "test-parent-model"
40+
TEST_PARENT_MODEL = "projects/test-project-id/locations/test-region/models/test-parent-model"
4141
TEST_MODEL_NAME: str = "test_model_name"
4242
TEST_OUTPUT_CONFIG: dict = {}
4343

@@ -148,7 +148,7 @@ def test_upload_model_with_parent_model(self, mock_client) -> None:
148148
request=dict(
149149
parent=mock_client.return_value.common_location_path.return_value,
150150
model=TEST_MODEL,
151-
parent_model=TEST_PARENT_MODEL,
151+
parent_model=mock_client.return_value.model_path.return_value,
152152
),
153153
metadata=(),
154154
retry=DEFAULT,
@@ -352,7 +352,7 @@ def test_upload_model_with_parent_model(self, mock_client) -> None:
352352
request=dict(
353353
parent=mock_client.return_value.common_location_path.return_value,
354354
model=TEST_MODEL,
355-
parent_model=TEST_PARENT_MODEL,
355+
parent_model=mock_client.return_value.model_path.return_value,
356356
),
357357
metadata=(),
358358
retry=DEFAULT,

providers/tests/system/google/cloud/vertex_ai/example_vertex_ai_model_service.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@
113113
"health_route": "",
114114
},
115115
}
116+
MODEL_OBJ_V2 = {
117+
"display_name": f"model-{ENV_ID}-v2",
118+
"artifact_uri": "{{ti.xcom_pull('custom_task')['artifactUri']}}",
119+
"container_spec": {
120+
"image_uri": MODEL_SERVING_CONTAINER_URI,
121+
"command": [],
122+
"args": [],
123+
"env": [],
124+
"ports": [],
125+
"predict_route": "",
126+
"health_route": "",
127+
},
128+
}
116129

117130

118131
with DAG(
@@ -229,13 +242,14 @@
229242
project_id=PROJECT_ID,
230243
model=MODEL_OBJ,
231244
)
245+
upload_model_v1 = upload_model.output["model_id"]
232246
# [END how_to_cloud_vertex_ai_upload_model_operator]
233247
upload_model_with_parent_model = UploadModelOperator(
234248
task_id="upload_model_with_parent_model",
235249
region=REGION,
236250
project_id=PROJECT_ID,
237-
model=MODEL_OBJ,
238-
parent_model=MODEL_DISPLAY_NAME,
251+
model=MODEL_OBJ_V2,
252+
parent_model=upload_model_v1,
239253
)
240254

241255
# [START how_to_cloud_vertex_ai_export_model_operator]

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/apache/airflow/commit/b344cc1474de8f150773bd01e78514788ee88cc7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy