aliyun / aliyun-odps-python-sdk

ODPS Python SDK and data analysis framework
http://pyodps.readthedocs.io
Apache License 2.0
434 stars 97 forks source link

跨project调用xflow任务时,打印sub_instance的logview地址是错误的,查询sub_instance的状态会报异常 #174

Closed DcSea closed 1 year ago

DcSea commented 2 years ago
odps = ODPS('xxxx', 'xxxxx',
            'odps_project',
            endpoint='http://service.odps.aliyun.com/api')

instance = odps.run_xflow(
        xflow_name="xflow_name",
        xflow_project="xflow_project",
        project="task_project",     
        parameters=params)  # 跟odps实例的project不相同,表示跨project调用xflow任务

for sub_instance_name, sub_instance in odps.iter_xflow_sub_instances(instance, project="task_project"):`
       print("sub instance:", sub_instance_name, sub_instance.get_logview_address())  # 打印的logview地址是错误的,浏览器中打开会报错
       print("sub instance:", sub_instance_name, sub_instance.status)  # 这里会报异常

异常信息如下:

Traceback (most recent call last):
  File "/Users/xxxxx/IdeaProjects/xxxxxx.py", line 150
    print(sub_instance_name, sub_instance.status)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/odps/models/core.py", line 120, in __getattribute__
    val = object.__getattribute__(self, attr)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/odps/models/instance.py", line 475, in status
    if self._status != Instance.Status.TERMINATED:
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/odps/models/core.py", line 124, in __getattribute__
    self.reload()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/odps/models/instance.py", line 277, in reload
    resp = self._client.get(self.resource())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/odps/rest.py", line 146, in get
    return self.request(url, 'get', stream=stream, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/odps/rest.py", line 142, in request
    errors.throw_if_parsable(res)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/odps/errors.py", line 75, in throw_if_parsable
    raise e
odps.errors.NoSuchObject: NoSuchObject: RequestId: 61E918B783C089A92BFA99D0
ODPS-0424111: Instance not found - '20220120080922302g7tc3yv03_4d5885f6_c656_4642_83f9_4bd78b8d45e8

建议的修复方案: 将odps.models.xflows 中 XFlows.get_xflow_sub_instances 方法修改如下:

def get_xflow_sub_instances(self, instance):
    inst_dict = compat.OrderedDict()`
    for x_result in filter(lambda xr: xr.node_type != 'Local',
                           six.itervalues(self.get_xflow_results(instance))):
        if x_result.node_type == 'Instance':
            inst_dict[x_result.name] = self.odps.get_instance(x_result.instance_id, project=self.parent)   # 增加 project入参
        elif x_result.node_type == 'SubWorkflow':
            sub_instance = self.odps.get_instance(x_result.instance_id, project=self.parent)   # 增加 project入参
            sub_inst_dict = self.odps.get_xflow_sub_instances(sub_instance, project=self.parent)   # 增加 project入参
            inst_dict.update(**sub_inst_dict)
    return inst_dict
wjsi commented 1 year ago

Fixed in v0.11.3. Thanks for the report.