Skip to content

Instantly share code, notes, and snippets.

@brianrodri
Last active February 15, 2021 12:12
Show Gist options
  • Save brianrodri/ce2adb87e0a37bfe213a166658e8d6be to your computer and use it in GitHub Desktop.
Save brianrodri/ce2adb87e0a37bfe213a166658e8d6be to your computer and use it in GitHub Desktop.
class ModelValidationError(object):
@property
def key(self):
return self.__class__.__name__
@property
def message(self):
return None
def __str__(self):
return '%s: %s' % (self.key, self.message) if self.message else self.key
def __eq__(self, other):
if self.__class__ is other.__class__:
return (self.key, self.message) == (other.key, other.message)
return NotImplemented
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return hash((self.__class__, self.key, self.message))
class TimeFieldModelValidationError(ValidationError):
def __init__(self, model):
self._message = (
'Entity ID %s: The created_on field has a value %s which '
'is greater than the value %s of last_updated field' % (
model.id, model.created_on, model.last_updated))
@property
def message(self):
return self._message
class ValidateModelTimeFields(beam.DoFn):
def process(self, model):
yield TimeFieldValidationError(model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment