wlanslovenija / django-tastypie-mongoengine

MongoEngine support for django-tastypie.
Other
73 stars 59 forks source link

thread unsafe problem #88

Open elephanter opened 9 years ago

elephanter commented 9 years ago

Hello. The problem located in MongoEngineResource._wrap_polymorphic method. In place, where resource overrides its self._meta.object_class, self._meta.queryset and other "low level" fields. So if I have polymorphic resource, maybe used in several places, I have chance to get wrong result. (what I saw in my project). While that fields is overridden in resource class the method _wrap_request is working wrong. I do not look closer but i think because of this lines

    if resource._meta.object_class is self._meta.object_class:
        return fun()

We entered in "fun()". But in other thread we have finish dehydration, and already returned all that fields back to remembered values in finally section in _wrap_polymorphic method. Dehydration will be wrong in that case. Basically resource will have no additional fields which added by nested mongoengine documents. (I use polymorphic resource for return different documents, derived from one basic mongoengine document... so, when this error happens, i have only root document fields in result).