clearml-server/apiserver/database/model/model_labels.py

15 lines
577 B
Python
Raw Normal View History

2021-01-05 14:28:49 +00:00
from apiserver.database.fields import NoneType, UnionField, SafeMapField
2019-06-10 21:24:35 +00:00
class ModelLabels(SafeMapField):
2019-06-10 21:24:35 +00:00
def __init__(self, *args, **kwargs):
super(ModelLabels, self).__init__(
field=UnionField(types=(int, NoneType)), *args, **kwargs
)
2019-06-10 21:24:35 +00:00
def validate(self, value):
super(ModelLabels, self).validate(value)
non_empty_values = list(filter(None, value.values()))
if non_empty_values and len(set(non_empty_values)) < len(non_empty_values):
2019-06-10 21:24:35 +00:00
self.error("Same label id appears more than once in model labels")