diff --git a/orator/orm/model.py b/orator/orm/model.py index f5e62887..8d9106c3 100644 --- a/orator/orm/model.py +++ b/orator/orm/model.py @@ -2401,7 +2401,7 @@ def get_attribute(self, key, original=None): :param key: The attribute to get :type key: str """ - in_attributes = key in self._attributes + in_attributes = key in self._attributes or self.is_fillable(key) if in_attributes: return self._get_attribute_value(key) @@ -2588,7 +2588,7 @@ def get_dates(self): def from_datetime(self, value): """ Convert datetime to a storable string. - + :param value: The datetime value :type value: pendulum.Pendulum or datetime.date or datetime.datetime diff --git a/tests/orm/test_model.py b/tests/orm/test_model.py index d81abaab..007699bd 100644 --- a/tests/orm/test_model.py +++ b/tests/orm/test_model.py @@ -912,6 +912,24 @@ def test_get_attribute_raise_attribute_error(self): except AttributeError: pass + def test_get_attribute_unknown_key(self): + model = OrmModelStub() + + try: + model.unknown_attribute + self.fail("AttributeError not raised") + except AttributeError: + pass + + def test_get_attribute_unknown_but_fillable_key(self): + model = OrmModelStub() + model.fillable(['unknown_attribute']) + + try: + model.unknown_attribute + except AttributeError: + self.fail("AttributeError raised for fillable key") + def test_increment(self): query = flexmock() model_mock = flexmock(OrmModelStub, new_query=lambda: query)