Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

资产硬件信息 `model` 内容过长导致 `保存失败`. #2655

Open
tupunco opened this issue May 4, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@tupunco
Copy link

commented May 4, 2019

资产硬件信息 model 内容过长导致保存失败.

使用版本

1.4.10-2

问题复现步骤
  • 这是修改 apps/assets/tasks.py 打印出来得 问题 数据截取, 中间有个 巨长 得空格
set_assets_hardware_info-asset k:`___model` v:`Lenovo System x3850 X6                               -[XXXXXXX]-`
  • 分析 数据模型 确认是 字段长度 不够, 导致 保存失败, 建议直接 128
model = models.CharField(max_length=54, null=True, blank=True, verbose_name=_('Model'))
具体表现[截图可能会更好些,最好能截全]
Task assets.tasks.update_asset_hardware_info_manual[b1dbadd9-d843-4a1e-a27f-b0791d15447e] raised unexpected: DataError(1406, "Data too long for column 'model' at row 1")
Traceback (most recent call last):
  File "/opt/py3/lib64/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
...
  File "/opt/jumpserver/apps/assets/tasks.py", line 144, in update_asset_hardware_info_manual
    update_assets_hardware_info_util(
...
  File "/opt/py3/lib64/python3.6/site-packages/celery/app/task.py", line 380, in __call__
    return self.run(*args, **kwargs)
  File "/opt/jumpserver/apps/assets/tasks.py", line 136, in update_assets_hardware_info_util
    result = task.run()
...
  File "/opt/jumpserver/apps/assets/tasks.py", line 110, in set_assets_hardware_info
  File "/opt/jumpserver/apps/orgs/mixins.py", line 85, in save
    return super().save(*args, **kwargs)
...
    _mysql.connection.query(self, query)
django.db.utils.DataError: (1406, "Data too long for column 'model' at row 1")
其他

[注:] 完成后请关闭 issue

@wojiushixiaobai

This comment has been minimized.

Copy link
Collaborator

commented May 4, 2019

@tupunco 是所有资产都这样吗?如果不是的话能不能告知一下具体出问题的资产设备型号,以及完整的截取数据,感谢

@tupunco

This comment has been minimized.

Copy link
Author

commented May 5, 2019

@tupunco 是所有资产都这样吗?如果不是的话能不能告知一下具体出问题的资产设备型号,以及完整的截取数据,感谢

不是所有资产, 目前发现的只有我贴的这个 型号CentOS6-物理机 会. 我这里有 4 台.
型号为 Lenovo System x3850 X6.

我上面贴的就是 model 字段内容 (XXXXXXX 部分估计为某 SN, 人工隐藏了, 不影响数据)

Lenovo System x3850 X6                               -[XXXXXXX]-

我修改了 /apps/assets/tasks.py#L76 文件, 暂时解决了问题:

model_pattern = re.compile(r'\s+')

___model = model_pattern.sub(' ', info.get('ansible_product_name', 'Unknown'))
@tupunco

This comment has been minimized.

Copy link
Author

commented May 5, 2019

日志打印代码:

# apps/assets/tasks.py#L105
for k, v in locals().items():
    if k.startswith('___'):
        logger.debug("set_assets_hardware_info-asset k:`{}` v:`{}`".format(k, v))
        setattr(asset, k.strip('_'), v)
@wojiushixiaobai

This comment has been minimized.

Copy link
Collaborator

commented May 5, 2019

@tupunco 明白了,这个可能还得看下有没有其他的字符串问题,不然只解决空格,出现其他的字符串也会报错,我反馈一下,看如何解决会比较好,麻烦老哥了

@tupunco

This comment has been minimized.

Copy link
Author

commented May 5, 2019

@tupunco 明白了,这个可能还得看下有没有其他的字符串问题,不然只解决空格,出现其他的字符串也会报错,我反馈一下,看如何解决会比较好,麻烦老哥了

我是 定向解决 问题 :), 感觉 扩容字段长度 是最保险的.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.