imbajin commented on code in PR #335:
URL: https://github.com/apache/hugegraph-ai/pull/335#discussion_r3264791481
##########
hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/fetch_graph_data.py:
##########
@@ -44,8 +46,18 @@ def res = [:];
return res;
"""
- result = self.graph.gremlin().exec(groovy_code)["data"]
+ try:
+ response = self.graph.gremlin().exec(groovy_code)
+ except Exception as e:
+ log.warning("Failed to fetch graph summary: %s", e)
+ return graph_summary
+ result = response.get("data") if isinstance(response, dict) else None
if isinstance(result, list) and len(result) > 0:
- graph_summary.update({key: result[i].get(key) for i, key in
enumerate(keys)})
+ graph_summary.update(
+ {
+ key: result[i].get(key) if i < len(result) and
isinstance(result[i], dict) else None
+ for i, key in enumerate(keys)
Review Comment:
‼️ 这里仍然假设 `data` 是 5 个按顺序排列的单字段 dict,但这个 Gremlin 脚本 `return res` 返回的是一个
map,常见响应会是 `{"data": [{"vertex_num": ..., "edge_num": ..., "vertices": ...,
"edges": ..., "note": ...}]}`。在这种形状下当前代码只会正确写入 `vertex_num`,后面的字段都会变成
`None`,会破坏图摘要以及后续依赖 `vertices` 的 vid-index 更新。建议显式兼容单行 summary
dict,并补一个该响应形状的回归测试。
```suggestion
result = response.get("data") if isinstance(response, dict) else None
if isinstance(result, list) and result:
if len(result) == 1 and isinstance(result[0], dict):
graph_summary.update({key: result[0].get(key) for key in
keys})
else:
graph_summary.update(
{
key: result[i].get(key) if i < len(result) and
isinstance(result[i], dict) else None
for i, key in enumerate(keys)
}
)
```
##########
hugegraph-python-client/src/pyhugegraph/utils/util.py:
##########
@@ -101,9 +101,15 @@ def __call__(self, response: requests.Response, method:
str, path: str):
log.info("Resource %s not found (404)", path)
else:
try:
- details = response.json().get("exception", "key
'exception' not found")
+ body = response.json()
+ details = (
+ body.get("exception")
+ or body.get("status", {}).get("message")
Review Comment:
‼️ 这里会把部分 HTTP 错误吞成 `{}`。HugeGraph/Gremlin 响应里的 `status` 可能是整数;当错误体没有
`exception` 且 `status` 不是 dict 时,`body.get("status", {}).get("message")` 会抛
`AttributeError`,随后被外层 broad `except Exception` 捕获并返回默认空结果,而不是继续抛
400/404/HTTPError。建议先判断 `status` 类型,并补一个 `status` 非 dict 的错误体回归测试。
```suggestion
body = response.json()
status = body.get("status")
status_message = status.get("message") if
isinstance(status, dict) else None
details = (
body.get("exception")
or status_message
or response.text
or "unknown error"
)
```
##########
hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/fetch_graph_data.py:
##########
@@ -44,8 +46,18 @@ def res = [:];
return res;
"""
- result = self.graph.gremlin().exec(groovy_code)["data"]
+ try:
+ response = self.graph.gremlin().exec(groovy_code)
+ except Exception as e:
+ log.warning("Failed to fetch graph summary: %s", e)
+ return graph_summary
Review Comment:
⚠️ 这里吞掉所有 Gremlin 执行异常后返回原始 `graph_summary`,会把“图服务不可达 / 权限错误 / Gremlin
执行失败”伪装成成功的空摘要。比如 `GetGraphIndexInfoFlow` 可能返回 `{}`,而 `UpdateVidEmbeddingsFlow`
可能继续跑到缺少 `vertices` 时才失败,错误位置会偏离真实原因。建议让连接/执行异常向上抛,或返回明确的错误状态并由调用方按失败处理,同时补一个
`gremlin().exec` 抛异常的测试。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]