diff --git a/cmdb-api/api/lib/cmdb/ci.py b/cmdb-api/api/lib/cmdb/ci.py index 88530d0..ad84126 100644 --- a/cmdb-api/api/lib/cmdb/ci.py +++ b/cmdb-api/api/lib/cmdb/ci.py @@ -187,8 +187,12 @@ class CIManager(object): return abort(404, 'CI <{0}> does not exist'.format(unique_value)) ci = CI.create(type_id=ci_type.id) + ci_type_attrs_name = [attr["name"] for attr in CITypeAttributeManager().get_attributes_by_type_id(ci_type.id)] value_manager = AttributeValueManager() for p, v in ci_dict.items(): + if p not in ci_type_attrs_name: + current_app.logger.warning('ci_type: {0} not has attribute {1}, please check!'.format(ci_type_name, p)) + continue try: value_manager.create_or_update_attr_value(p, v, ci, _no_attribute_policy) except BadRequest as e: diff --git a/cmdb-api/api/lib/cmdb/value.py b/cmdb-api/api/lib/cmdb/value.py index 2b53a22..10c54a0 100644 --- a/cmdb-api/api/lib/cmdb/value.py +++ b/cmdb-api/api/lib/cmdb/value.py @@ -160,12 +160,13 @@ class AttributeValueManager(object): self._write_change(ci.id, attr.id, OperateType.ADD, None, value) else: - if not value and attr.value_type != ValueTypeEnum.TEXT: - existed_attr.delete() - else: - existed_attr.update(value=value) + if existed_value != value: + if value != 0 and not value and attr.value_type != ValueTypeEnum.TEXT: + existed_attr.delete() + else: + existed_attr.update(value=value) - self._write_change(ci.id, attr.id, OperateType.UPDATE, existed_value, value) + self._write_change(ci.id, attr.id, OperateType.UPDATE, existed_value, value) @staticmethod def delete_attr_value(attr_id, ci_id):