Skip to content

Commit

Permalink
fix(api): unique constraint (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
pycook committed May 2, 2024
1 parent ef25c94 commit 095190a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cmdb-api/api/lib/cmdb/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,11 @@ def _valid_unique_constraint(type_id, ci_dict, ci_id=None):
ci_ids = None
for attr_id in constraint.attr_ids:
value_table = TableMap(attr_name=id2name[attr_id]).table

_ci_ids = set([i.ci_id for i in value_table.get_by(attr_id=attr_id,
to_dict=False,
value=ci_dict.get(id2name[attr_id]) or None)])
values = value_table.get_by(attr_id=attr_id,
value=ci_dict.get(id2name[attr_id]) or None,
only_query=True).join(
CI, CI.id == value_table.ci_id).filter(CI.type_id == type_id)
_ci_ids = set([i.ci_id for i in values])
if ci_ids is None:
ci_ids = _ci_ids
else:
Expand Down

0 comments on commit 095190a

Please sign in to comment.