# Buggy code
def job_get_job_task_detail(request, biz_cc_id, task_id):
    client = get_client_by_request(request)
    job_result = client.job.get_job_detail(
        {"bk_biz_id": biz_cc_id, "bk_job_id": task_id}
    )
    if not job_result["result"]:
        message = _(
            "查询作业平台(JOB)的作业模板详情[app_id=%s]接口job.get_task_detail返回失败: %s"
        ) % (biz_cc_id, job_result["message"])
        logger.error(message)
        result = {"result": False, "data": [], "message": message}
        return JsonResponse(result)

    job_step_type_name = {1: _("脚本"), 2: _("文件"), 4: "SQL"}
    task_detail = job_result["data"]
    global_var = []
    steps = []
    for var in task_detail.get("global_vars", []):
        # 1-字符串, 2-IP, 3-索引数组, 4-关联数组
        if var["type"] in [JOB_VAR_TYPE_STR, JOB_VAR_TYPE_IP, JOB_VAR_TYPE_ARRAY]:
            value = var.get("value", "")
        else:
            value = [
                "{plat_id}:{ip}".format(
                    plat_id=ip_item["bk_cloud_id"], ip=ip_item["ip"]
                )
                for ip_item in var.get("ip_list", [])
            ]
        global_var.append(
            {
                "id": var["id"],
                # 全局变量类型：1:云参, 2:上下文参数，3:IP
                "category": var.get("category", 1),
                "name": var["name"],
                "type": var["type"],
                "value": value,
                "description": var["description"],
            }
        )
    for info in task_detail.get("steps", []):
        # 1-执行脚本, 2-传文件, 4-传SQL
        steps.append(
            {
                "stepId": info["step_id"],
                "name": info["name"],
                "scriptParams": info.get("script_param", ""),
                "account": info.get("account", ""),
                "ipList": "",
                "type": info["type"],
                "type_name": job_step_type_name.get(info["type"], info["type"]),
            }
        )
    return JsonResponse(
        {"result": True, "data": {"global_var": global_var, "steps": steps}}
    )


# Traceback (ImportError)
------STARTING: Migrate Database------
Traceback (most recent call last):
File "manage.py", line 27, in <module>
execute_from_command_line(sys.argv)
File "/cache/.bk/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/cache/.bk/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 328, in execute
django.setup()
File "/cache/.bk/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/cache/.bk/env/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/cache/.bk/env/lib/python2.7/site-packages/django/apps/config.py", line 112, in create
mod = import_module(mod_path)
File "/cache/.bk/env/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/data/app/code/pipeline/apps.py", line 18, in <module>
from rediscluster import StrictRedisCluster
File "/cache/.bk/env/lib/python2.7/site-packages/rediscluster/__init__.py", line 7, in <module>
from .client import StrictRedisCluster, RedisCluster
File "/cache/.bk/env/lib/python2.7/site-packages/rediscluster/client.py", line 10, in <module>
from .connection import (
File "/cache/.bk/env/lib/python2.7/site-packages/rediscluster/connection.py", line 11, in <module>
from .nodemanager import NodeManager
File "/cache/.bk/env/lib/python2.7/site-packages/rediscluster/nodemanager.py", line 12, in <module>
from redis._compat import b, unicode, bytes, long, basestring
ImportError: cannot import name b
------FAILURE: Migrate Database------

# Fixed code
def job_get_job_task_detail(request, biz_cc_id, task_id):
    client = get_client_by_user(request.user.username)
    job_result = client.job.get_job_detail(
        {"bk_biz_id": biz_cc_id, "bk_job_id": task_id}
    )
    if not job_result["result"]:
        message = _(
            "查询作业平台(JOB)的作业模板详情[app_id=%s]接口job.get_task_detail返回失败: %s"
        ) % (biz_cc_id, job_result["message"])
        logger.error(message)
        result = {"result": False, "data": [], "message": message}
        return JsonResponse(result)

    job_step_type_name = {1: _("脚本"), 2: _("文件"), 4: "SQL"}
    task_detail = job_result["data"]
    global_var = []
    steps = []
    for var in task_detail.get("global_vars", []):
        # 1-字符串, 2-IP, 3-索引数组, 4-关联数组
        if var["type"] in [JOB_VAR_TYPE_STR, JOB_VAR_TYPE_IP, JOB_VAR_TYPE_ARRAY]:
            value = var.get("value", "")
        else:
            value = [
                "{plat_id}:{ip}".format(
                    plat_id=ip_item["bk_cloud_id"], ip=ip_item["ip"]
                )
                for ip_item in var.get("ip_list", [])
            ]
        global_var.append(
            {
                "id": var["id"],
                # 全局变量类型：1:云参, 2:上下文参数，3:IP
                "category": var.get("category", 1),
                "name": var["name"],
                "type": var["type"],
                "value": value,
                "description": var["description"],
            }
        )
    for info in task_detail.get("steps", []):
        # 1-执行脚本, 2-传文件, 4-传SQL
        steps.append(
            {
                "stepId": info["step_id"],
                "name": info["name"],
                "scriptParams": info.get("script_param", ""),
                "account": info.get("account", ""),
                "ipList": "",
                "type": info["type"],
                "type_name": job_step_type_name.get(info["type"], info["type"]),
            }
        )
    return JsonResponse(
        {"result": True, "data": {"global_var": global_var, "steps": steps}}
    )