Search code examples
python-3.xmongodbrestflaskeve

Upload LIST of Media files to Mongodb using EVE API framework return maximum recursion Error


I have EVE up and running and have my schema defined as per docs:

accounts = {
'name': {'type': 'string'},
'multimedia': {'type': 'media'}
}

I can send a multipart/form-data request with one file but I want to send LIST of Media files. I already followed the documentation and added the following settings:

# This flag allows passthrough from the driver of additional meta fields. 
# For example, using the MongoDB driver, fields like content_type, name and 
# length can be added to this list and will be passed-through from the 
# underlying driver.When EXTENDED_MEDIA_INFO is used the field will be a 
# dictionary whereas the file itself is stored under the file key and other 
# keys are the meta fields.
EXTENDED_MEDIA_INFO = ['content_type', 'name', 'length']

# For multipart/form-data uploads to treat the incoming fields as JSON encoded strings 
# and still be able to validate your fields.
MULTIPART_FORM_FIELDS_AS_JSON = True

# When using lists of media, there is no way to submit these in the default configuration. 
# Enable AUTO_COLLAPSE_MULTI_KEYS and AUTO_CREATE_LISTS to make this possible. This allows
# to send multiple values for one key in multipart/form-data requests and in this way upload 
# a list of files.
AUTO_COLLAPSE_MULTI_KEYS = True 
AUTO_CREATE_LISTS = True

Now I try to send more than one file I get the following Error:

{
"status": "ERR",
    "error": {
        "code": 400,
        "message": "An exception occurred: maximum recursion depth exceeded while calling a Python 
         object"
    }
}

Any suggestions? I use this snippet to test:

curl -X PATCH -H "Authorization: Bearer g6SZBmknNLf401915dNSJi4WNK72pk" 
-H "Content-Type: multipart/form-data"
-F "multimedia=@text.json" -F "mutlimedia=@event.json" 
http://localhost:5000/endpoint/_id

{"status": "ERR", "error": {"code": 400, "message": "An exception occurred: 
maximum recursion depth exceeded while calling a Python object"}}

Eve logs:

Traceback (most recent call last):

File "/usr/local/lib/python3.7/site-packages/eve/methods/patch.py", line 
244, in patch_internal issues = validator.errors
File "/usr/local/lib/python3.7/site-packages/cerberus/validator.py", line 
464, in errors return self.error_handler(self._errors)
File "/usr/local/lib/python3.7/site-packages/cerberus/errors.py", line 
493, in __call__self.extend(errors)
File "/usr/local/lib/python3.7/site-packages/cerberus/errors.py", line 
397, in extend self.add(error)
File "/usr/local/lib/python3.7/site-packages/cerberus/errors.py", line 
510, in add error = deepcopy(error)
File "/usr/local/lib/python3.7/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/local/lib/python3.7/copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "/usr/local/lib/python3.7/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/usr/local/lib/python3.7/copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/lib/python3.7/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/local/lib/python3.7/copy.py", line 281, in _reconstruct
if hasattr(y, '__setstate__'):
File "/usr/local/lib/python3.7/site-packages/werkzeug/datastructures.py", 
line 2821, in __getattr__return getattr(self.stream, name)
File "/usr/local/lib/python3.7/site-packages/werkzeug/datastructures.py", 
line 2821, in __getattr__return getattr(self.stream, name)
File "/usr/local/lib/python3.7/site-packages/werkzeug/datastructures.py", 
line 2821, in __getattr__return getattr(self.stream, name)
[Previous line repeated 485 more times]
RecursionError: maximum recursion depth exceeded while calling a Python 
object

An issue has been submitted to Eve project Github repo.


Solution

  • I followed the PR for the feature and now it works like charm! https://github.com/pyeve/eve/pull/933