Skip to content

Validate after setting multiple fields at once #72

@bharathbhushan1

Description

@bharathbhushan1

The requirement is to set multiple fields which have individual validators where there could be a period where the invariants are not satisfied but at the end of the "transaction", all validators are satisfied. Is there a way to get this done? If not, can we add this as an enhancement?

class Test(object):
  a = field(type_hint=six.integer_types, native=False, default=2)
  b = field(type_hint=six.integer_types, native=False, default=1)

  @a.validator()
  def validate_a(self, new_a):
    return new_a == self.b * 2

  @b.validator()
  def validate_b(self, new_b):
    return new_b == self.a / 2

t = Test()
# Start transaction
t.a = 100   # Fails because the invariant is not satisfied
t.b = 50
# End of transaction

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions