Changeset 18:40ba502fe87e in mailjam


Ignore:
Timestamp:
May 22, 2012, 1:26:27 PM (12 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Fixed a bug in the code that loads python objects from json dumps.

This bug was raising TypeError exceptions when the dumped object contained
more attributes defined in the init method than the arguments accepted
by the init method itself.

(You can reproduce this error in previous revisions of the code by dumping
a mailjam.models.MailingList object and then trying to load it from the
json dump).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mailjam/storage.py

    r16 r18  
    1111"""
    1212
    13 import os, errno, json
     13import os, errno, json, inspect
    1414
    1515
     
    6363            module = __import__(module_name)
    6464            class_ = getattr(module, class_name)
     65            # inspect the class __init__ method, getting a list of
     66            # accepted/valid arguments.
     67            valid_args = inspect.getargspec(class_.__init__)
     68            # then, only accepted parameters will be deserialized
    6569            args = dict((key.encode('ascii'), value) \
    66                         for key, value in jobj.items())
     70                        for key, value in jobj.items() if key in valid_args[0])
    6771            return class_(**args)
    6872        return jobj
Note: See TracChangeset for help on using the changeset viewer.