diff options
| author | Ewoud Kohl van Wijngaarden | 2012-01-09 15:56:41 +0100 |
|---|---|---|
| committer | Ewoud Kohl van Wijngaarden | 2012-01-09 15:56:41 +0100 |
| commit | 0d64b4a704eed2fb483de66a7e7271ac83144530 (patch) | |
| tree | 2ab6bbb9db50d4ca45810313eacf95546a97f015 | |
| parent | e712ab0ba193e22e121fcd56dfea166bd84f57ed (diff) | |
| download | django-rest-framework-0d64b4a704eed2fb483de66a7e7271ac83144530.tar.bz2 | |
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.
| -rw-r--r-- | djangorestframework/serializer.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/djangorestframework/serializer.py b/djangorestframework/serializer.py index 429adea2..4e1c6b80 100644 --- a/djangorestframework/serializer.py +++ b/djangorestframework/serializer.py @@ -230,11 +230,10 @@ class Serializer(object): # serialize each required field for fname in fields: 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 - 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: # check for a key 'fname' on the instance obj = instance[fname] |
