Skip to content

Python 2 regression from 3.7.0 - AttributeError: 'functools.partial' object has no attribute '__module__' #5509

Closed
@jakul

Description

@jakul

I have a strange issue which has started to show since DRF 3.7. The json.load in my runtime is a partial, which then causes a crash when I import from rest_framework.utils import json. I'm not sure what package is wrapping json.load to make it a partial, but it wasn't a problem in DRF 3.6 or before. @rpkilby This seems to be caused by the work you did to add the utils.json module.

Steps to reproduce

In [1]: import json

In [2]: from functools import partial

In [3]: setattr(json, 'load', partial(json.load))

In [4]: json.load
Out[4]: <functools.partial at 0x10af90f70>

In [5]: from rest_framework.utils import json
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-88089cf65770> in <module>()
----> 1 from rest_framework.utils import json

/Users/craig/.virtualenvs/tester/lib/python2.7/site-packages/rest_framework/utils/json.py in <module>()
     29
     30
---> 31 @functools.wraps(json.load)
     32 def load(*args, **kwargs):
     33     kwargs.setdefault('parse_constant', strict_constant)

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.pyc in update_wrapper(wrapper, wrapped, assigned, updated)
     31     """
     32     for attr in assigned:
---> 33         setattr(wrapper, attr, getattr(wrapped, attr))
     34     for attr in updated:
     35         getattr(wrapper, attr).update(getattr(wrapped, attr, {}))

AttributeError: 'functools.partial' object has no attribute '__module__'

Expected behavior

No exception thrown on import.

Actual behavior

Exception is thrown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions