mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 21:24:33 +03:00
Make a nested if flat
This is a possible fix for issue #73. The problem occurs when the first if-statement is true, but the second is not. This results into the variable obj not being set. This commit solves it by removing that branch.
This commit is contained in:
parent
e712ab0ba1
commit
0d64b4a704
|
@ -230,10 +230,9 @@ class Serializer(object):
|
||||||
# serialize each required field
|
# serialize each required field
|
||||||
for fname in fields:
|
for fname in fields:
|
||||||
try:
|
try:
|
||||||
if hasattr(self, smart_str(fname)):
|
if inspect.ismethod(getattr(self, fname, None)) and \
|
||||||
|
len(inspect.getargspec(getattr(self, fname))[0]) == 2:
|
||||||
# check first for a method 'fname' on self first
|
# check first for a method 'fname' on self first
|
||||||
meth = getattr(self, fname)
|
|
||||||
if inspect.ismethod(meth) and len(inspect.getargspec(meth)[0]) == 2:
|
|
||||||
obj = meth(instance)
|
obj = meth(instance)
|
||||||
elif hasattr(instance, '__contains__') and fname in instance:
|
elif hasattr(instance, '__contains__') and fname in instance:
|
||||||
# check for a key 'fname' on the instance
|
# check for a key 'fname' on the instance
|
||||||
|
|
Loading…
Reference in New Issue
Block a user