mirror of
https://github.com/veops/cmdb.git
synced 2025-08-26 01:29:31 +08:00
fix(api): 使用 ast.literal_eval 代替 eval,取消不正确的计算属性值返回。 (#688)
* fix(api): 使用 ast.literal_eval 代替 eval,取消不正确的计算属性值返回。 * fix(api): 修复属性值计算逻辑,直接返回渲染结果。
This commit is contained in:
@@ -180,14 +180,15 @@ class AttributeValueManager(object):
|
||||
|
||||
@staticmethod
|
||||
def _compute_attr_value_from_expr(expr, ci_dict):
|
||||
t = jinja2.Template(expr).render(ci_dict)
|
||||
|
||||
try:
|
||||
return eval(t)
|
||||
result = jinja2.Template(expr).render(ci_dict)
|
||||
return result
|
||||
except Exception as e:
|
||||
current_app.logger.warning(str(e))
|
||||
return t
|
||||
|
||||
current_app.logger.warning(
|
||||
f"Expression evaluation error - Expression: '{expr}'"
|
||||
f"Input parameters: {ci_dict}, Error type: {type(e).__name__}, Error message: {str(e)}"
|
||||
)
|
||||
return None
|
||||
@staticmethod
|
||||
def _compute_attr_value_from_script(script, ci_dict):
|
||||
script = jinja2.Template(script).render(ci_dict)
|
||||
|
Reference in New Issue
Block a user