Skip to content

Commit

Permalink
Return None, instead of raising AttributeError on MarkupTextDescripto…
Browse files Browse the repository at this point in the history
…r if no instance (#66)

Django 1.11.2 get_or_create object is passing in None instance
  • Loading branch information
reinbach authored and ellmetha committed Jun 8, 2017
1 parent 04716c3 commit a183fb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion machina/models/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, field):

def __get__(self, instance, owner):
if instance is None:
raise AttributeError(_('Can only be accessed via an instance.'))
return None
raw = instance.__dict__[self.field.name]
if raw is None:
return None
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/forum/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ def test_can_send_a_specific_signal_when_a_forum_is_moved(self):
self.top_level_forum.parent = self.top_level_cat
self.top_level_forum.save()
assert receiver.call_count == 1

def test_get_or_create(self):
forum, created = Forum.objects.get_or_create(name="Test Forum", type=0)
assert created is True
assert isinstance(forum, Forum)
assert forum.name == "Test Forum"

0 comments on commit a183fb4

Please sign in to comment.