Skip to content

Commit 61a3071

Browse files
dsanders11sabricot
authored andcommitted
Handle nested OneToOneField when related object doesn't exist (#85)
1 parent af77e5f commit 61a3071

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

django_elasticsearch_dsl/fields.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import collections
22
from types import MethodType
33

4+
from django.core.exceptions import ObjectDoesNotExist
45
from django.db import models
56
from django.db.models.fields.files import FieldFile
67
from django.utils.encoding import force_text
@@ -56,6 +57,8 @@ def get_value_from_instance(self, instance, field_value_to_ignore=None):
5657
):
5758
try:
5859
instance = getattr(instance, attr)
60+
except ObjectDoesNotExist:
61+
return None
5962
except (TypeError, AttributeError):
6063
try:
6164
instance = instance[int(attr)]

0 commit comments

Comments
 (0)