Mirror of https://github.com/roostorg/osprey github.com/roostorg/osprey
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: add pydantic validator to `EntityT` (#28)

authored by

ayu and committed by
GitHub
701f3d58 79a07d78

+16
+16
osprey_worker/src/osprey/engine/language_types/entities.py
··· 42 42 # the real type. Assumes that this has no subclasses. 43 43 return typing_inspect.get_args(cls)[0] 44 44 45 + @classmethod 46 + def __get_validators__(cls): 47 + """Pydantic v1 validator""" 48 + yield cls.validate 49 + 50 + @classmethod 51 + def validate(cls, v): 52 + """Validate and convert to EntityT""" 53 + if isinstance(v, cls): 54 + return v 55 + if isinstance(v, dict): 56 + if 'type' in v and 'id' in v: 57 + return cls(type=v['type'], id=v['id']) 58 + raise TypeError(f'EntityT expects dict with "type" and "id" keys, got {v}') 59 + raise TypeError(f'EntityT expected EntityT or dict; got {type(v)}') 60 + 45 61 46 62 # Make sure this looks as it's used in the Osprey language when used in error messages. 47 63 EntityT.__name__ = 'Entity'