Skip to content

Commit

Permalink
Use capability ID to validate
Browse files Browse the repository at this point in the history
Change-Id: Iddbc13299295f8790678d33d34c391aa6d090d1d
  • Loading branch information
AnishReddyRavula committed Mar 19, 2024
1 parent 4761fa7 commit 74642e1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions blazar/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,23 +314,23 @@ class ComputeHostExtraCapability(mb.BlazarBase, mb.SoftDeleteMixinWithUuid):
def to_dict(self):
return super(ComputeHostExtraCapability, self).to_dict()

@validates('capability_value')
def validate_capability_value(self, key, capability_value):
@validates('capability_id')
def validate_capability_value(self, key, capability_id):
from blazar.db.sqlalchemy import facade_wrapper
session = facade_wrapper.get_session()
extra_capability = session.query(ExtraCapability).filter_by(id=self.capability_id).first()
extra_capability = session.query(ExtraCapability).filter_by(id=capability_id).first()
if extra_capability and extra_capability.is_unique:
existing_capability = (
session.query(ComputeHostExtraCapability).filter_by(computehost_id=self.computehost_id,
capability_id=self.capability_id).first()
)
session.query(ComputeHostExtraCapability).filter_by(
capability_id=extra_capability.id, capability_value=self.capability_value, deleted=None)
).first()
if existing_capability:
raise ValueError(
f"{extra_capability.capability_name} must be unique. "
f"Please select unique {extra_capability.capability_name} for "
f"{self.computehost_id}"
)
return capability_value
return capability_id



Expand Down

0 comments on commit 74642e1

Please sign in to comment.