mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Catch exception raised for the reverse access of a OneToOneField.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
# Django
|
# Django
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
# Django REST framework
|
# Django REST framework
|
||||||
from rest_framework import serializers, pagination
|
from rest_framework import serializers, pagination
|
||||||
@@ -98,13 +99,17 @@ class BaseSerializer(serializers.ModelSerializer):
|
|||||||
# method for each object.
|
# method for each object.
|
||||||
summary_fields = {}
|
summary_fields = {}
|
||||||
for fk in SUMMARIZABLE_FKS:
|
for fk in SUMMARIZABLE_FKS:
|
||||||
fkval = getattr(obj, fk, None)
|
try:
|
||||||
if fkval is not None:
|
fkval = getattr(obj, fk, None)
|
||||||
summary_fields[fk] = {}
|
if fkval is not None:
|
||||||
for field in SUMMARIZABLE_FIELDS:
|
summary_fields[fk] = {}
|
||||||
fval = getattr(fkval, field, None)
|
for field in SUMMARIZABLE_FIELDS:
|
||||||
if fval is not None:
|
fval = getattr(fkval, field, None)
|
||||||
summary_fields[fk][field] = fval
|
if fval is not None:
|
||||||
|
summary_fields[fk][field] = fval
|
||||||
|
# Can be raised by the reverse accessor for a OneToOneField.
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
pass
|
||||||
return summary_fields
|
return summary_fields
|
||||||
|
|
||||||
def get_creation_date(self, obj):
|
def get_creation_date(self, obj):
|
||||||
|
|||||||
Reference in New Issue
Block a user