noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.73k stars 507 forks source link

`RuntimeError: dictionary changed size during iteration` during deepcopy operation #379

Open justin1364 opened 6 years ago

justin1364 commented 6 years ago

We spuriously, yet regularly, are seeing this error when running Flask-RESTplus. Anyone have any idea how to fix this?

Traceback (most recent call last):
  File "lib/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "lib/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "lib/flask_restplus/api.py", line 313, in wrapper
    resp = resource(*args, **kwargs)
  File "lib/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "lib/flask_restplus/resource.py", line 42, in dispatch_request
    self.validate_payload(meth)
  File "lib/flask_restplus/resource.py", line 88, in validate_payload
    self.__validate_payload(expect, collection=False)
  File "lib/flask_restplus/resource.py", line 73, in __validate_payload
    expect.validate(data, self.api.refresolver, self.api.format_checker)
  File "lib/flask_restplus/api.py", line 654, in refresolver
    self._refresolver = RefResolver.from_schema(self.__schema__)
  File "lib/werkzeug/utils.py", line 73, in __get__
    value = self.func(obj)
  File "lib/flask_restplus/api.py", line 472, in __schema__
    self._schema = Swagger(self).as_dict()
  File "lib/flask_restplus/swagger.py", line 167, in as_dict
    paths[extract_path(url)] = self.serialize_resource(ns, resource, url, kwargs)
  File "lib/flask_restplus/swagger.py", line 306, in serialize_resource
    path[method] = self.serialize_operation(doc, method)
  File "lib/flask_restplus/swagger.py", line 312, in serialize_operation
    'responses': self.responses_for(doc, method) or None,
  File "lib/flask_restplus/swagger.py", line 397, in responses_for
    responses[code]['schema'] = self.serialize_schema(model)
  File "lib/flask_restplus/swagger.py", line 432, in serialize_schema
    self.register_model(model)
  File "lib/flask_restplus/swagger.py", line 461, in register_model
    self.register_field(field)
  File "lib/flask_restplus/swagger.py", line 471, in register_field
    self.register_field(field.container)
  File "/lib/flask_restplus/swagger.py", line 469, in register_field
    self.register_model(field.nested)
  File "lib/flask_restplus/fields.py", line 207, in nested
    return getattr(self.model, 'resolved', self.model)
  File "lib/flask_restplus/model.py", line 164, in resolved
    resolved = copy.deepcopy(self)
  File "python27_dist/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "python27_dist/lib/python2.7/copy.py", line 357, in _reconstruct
    value = deepcopy(value, memo)
  File "python27_dist/lib/python2.7/copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "python27_dist/lib/python2.7/copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "python27_dist/lib/python2.7/copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "python27_dist/lib/python2.7/copy.py", line 256, in _deepcopy_dict
    for key, value in x.iteritems():
RuntimeError: dictionary changed size during iteration
eirabie commented 6 years ago

Did you end up finding a solution for this?

justin1364 commented 6 years ago

Nope... still see it from time to time.

AdeyinkaAdegbenro commented 6 years ago

Me too

nlohmann commented 6 years ago

Same problem here. Any hints greatly appreciated!

prernadubey commented 5 years ago

Same issue I am facing..Did any one got solution for this?

bowd commented 5 years ago

no solution here but I'm thinking it probably has something to do with gunicorn + gthread worker. Feels like a not thread-safe operation happening when workers get spun up with the preload_app option. But this is just my spider-sense tingling, haven't research.