joshmarshall/mogo

Missing Fields Error Reporting

hiwaylon opened this issue · 0 comments

Description

Accessing ignored fields raises cryptic errors.

Details

When ignored fields (named with an _) are accessed, a KeyError is raised. This exception should be more helpful, e.g. InvalidFieldError or possibly AccessingIgnoredFieldError in this case.

Example

class SomeModel(mogo.Model):
    _secret = mogo.Field(dict, required=True, default=dict)

    def do_secret_stuff(self):
        my_model._secret.get("stuff", "")

Will produce:

    mogo/mogo/field.py line 31 in __get__
      value = self._get_value(instance)
    mogo/mogo/field.py line 41 in _get_value
      field_name = self._get_field_name(instance)
    mogo/mogo/field.py line 37 in _get_field_name
      return fields[self.id]
   KeyError: 37806672