Skip to content

Instantly share code, notes, and snippets.

@amcgregor
Last active May 29, 2019 20:04
Show Gist options
  • Save amcgregor/ae3f6dc61a84abba6b918d74938e4ee4 to your computer and use it in GitHub Desktop.
Save amcgregor/ae3f6dc61a84abba6b918d74938e4ee4 to your computer and use it in GitHub Desktop.
from marrow.schema import Attribute
from marrow.schema.validate import Validator
from marrow.schama.validate.exc import Concern
class EqualsOther(Validator):
"""Ensure the value used matches an existing value from another attribute on the same object."""
other = Attribute()
def validate(self, value, context):
other = getattr(context, self.other, None)
if value != other:
raise Concern("Values do not match.")
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment