-
-
Notifications
You must be signed in to change notification settings - Fork 630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race Conditions in Marshmallow - Context Not thread safe? #1825
Comments
I suspect the same schema instance is shared among all requests. This shouldn't happen if the view is passed a schema class and instantiates the schema on each request. Please post a sample code to show the way you use the schema in the view function. |
Example:
I had the MySchema initialisation outside of the Get Function / FlaskView, which might have caused the problem? |
Exactly. This is not exactly a marshmallow thread-safety issue. If a object instance is shared by multiple threads, setting an attribute in one thread modifies the object for the other threads as well. (Things can get tricky with nested schemas, though: #1617.) |
Hello everybody,
I am having a serious problem. We are serializing a list of objects up to 100 objects at a time/per request and we have some custom field methods.
In these field methods, we pass the user_id in the context and perform some queries specific to that user_id. Now... I have noticed that sometimes this extra object field is wrong and after much investigation I found out that in some cases (within the list of objects in the same request!) the user_id was wrong and suddenly changed. The user_id passed through the context changed mid serialization of these 100 objects... I checked this "wrong" user and saw that his/her last activity was the same as mine what leads me to the conclusion that for some reason Marshmallow is not thread-safe and there is a race condition? Here is an example of my code:
I am unsure how to proceed now. I would need to fix this as soon as possible.
Thanks in advance.
The text was updated successfully, but these errors were encountered: