Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

get_attribute to consider fillable attributes #390

Open
wants to merge 1 commit into
base: 0.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions orator/orm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions tests/orm/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down