Skip to content

Commit 2e6d39d

Browse files
committed
Merge pull request #2754 from bleib1dj/enhancement_dont_require_pk_strictly_related
Enhancement dont require pk strictly related #2745
2 parents 6333e48 + b1c1867 commit 2e6d39d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

rest_framework/relations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def get_url(self, obj, view_name, request, format):
196196
attributes are not configured to correctly match the URL conf.
197197
"""
198198
# Unsaved objects will not yet have a valid URL.
199-
if obj.pk is None:
199+
if hasattr(obj, 'pk') and obj.pk is None:
200200
return None
201201

202202
lookup_value = getattr(obj, self.lookup_field)
@@ -361,7 +361,7 @@ def to_internal_value(self, data):
361361

362362
def get_attribute(self, instance):
363363
# Can't have any relationships if not created
364-
if not instance.pk:
364+
if hasattr(instance, 'pk') and instance.pk is None:
365365
return []
366366

367367
relationship = get_attribute(instance, self.source_attrs)

0 commit comments

Comments
 (0)