googleapis / googleapis/python-aiplatform

Execution.create() fails with 503 due to credentials annotation typo

未关闭 适合新手
#6,610 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
api: vertex-ai
主要语言
Python
星标
905
派生
465
平均合并
1 天 13 小时
30 天内合并 PR
44

描述

## Bug

`google.cloud.aiplatform.metadata.execution.Execution.create()` fails with a 503 error when called without explicitly passing `credentials=`:

```
503 Getting metadata from plugin failed with error: before_request
```

### Root cause

Two issues in `google/cloud/aiplatform/metadata/execution.py`:

**1. `credentials` parameter annotation typo (high severity)**

Both `create()` and `_create()` use `=` instead of `:` for the credentials type annotation:

```python
# Current (broken) -- execution.py lines 103, 181:
credentials=Optional[auth_credentials.Credentials],

# Should be (matches artifact.py, context.py):
credentials: Optional[auth_credentials.Credentials] = None,
```

Because `=` is used instead of `:`, the default value is the `typing.Optional[google.auth.credentials.Credentials]` type object itself (a `_UnionGenericAlias`), not `None`. This non-None type object is passed down to the gRPC auth stack, which attempts to call `.before_request()` on it, producing the 503.

Introduced in PR #1410 (June 2022). `artifact.py` and `context.py` both have the correct `: ... = None` syntax.

**2. Missing `ensure_default_metadata_store_exists()` call (lower severity)**

`Artifact.create()` calls `metadata_store._MetadataStore.ensure_default_metadata_store_exists()` before delegating to `_create()`. `Execution.create()` skips this call entirely. This means standalone `Execution.create()` will also fail if the default metadata store hasn't been implicitly created by a prior `Artifact.create()` or `aiplatform.init(experiment=...)` call. `Context.create()` has the same gap but is not addressed here.

### Reproduction

```python
from google.cloud import aiplatform
from google.cloud.aiplatform.metadata import execution as metadata_execution
from google.cloud.aiplatform.compat.types import execution as gca_execution

aiplatform.init(project="my-project", location="us-central1")

# This fails with 503:
exec_obj = metadata_execution.Execution.create(
schema_title="system.CustomJob",
resource_id="test-execution",
display_name="test",
state=gca_execution.Execution.State.COMPLETE,
metadata={"component_type": "custom_job"},
)
```

### Workaround

Call `ensure_default_metadata_store_exists()` manually, which also initializes credentials properly:

```python
from google.cloud.aiplatform.metadata import metadata_store
metadata_store._MetadataStore.ensure_default_metadata_store_exists(
project="my-project", location="us-central1",
)
# Now Execution.create() works
```

### Fix

Two changes to `execution.py`:
1. Fix `credentials=Optional[auth_credentials.Credentials]` to `credentials: Optional[auth_credentials.Credentials] = None` on both `create()` and `_create()`
2. Add the `ensure_default_metadata_store_exists()` call in `create()` (matching `Artifact.create()`)

### Environment

- google-cloud-aiplatform 1.140.0
- Python 3.13.2
- macOS / Vertex AI training containers (both affected)

贡献指南

打开贡献指南

调研方向

从 google/cloud/aiplatform/metadata/execution.py 中的 create() 和 _create() 定义开始,然后将它们的 credentials 参数和初始化流程与 artifact.py 和 context.py 进行比较。运行提供的独立 Execution.create() 复现;当 annotation 和默认 metadata-store 设置符合 issue 要求的行为,并且调用不再因报告的 503 而失败时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
google-cloud, python
领域
api, machine-learning
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
冷清
描述清晰度
描述清楚
新手友好度
78/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。