From aedfcf164bae218f8fae3f4dd9293decc780acf8 Mon Sep 17 00:00:00 2001 From: Pat Newell Date: Fri, 5 Feb 2021 08:30:16 -0500 Subject: [PATCH] get_attribute to consider fillable attributes --- orator/orm/model.py | 4 ++-- tests/orm/test_model.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) 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)