DEV Community

Jay Z
Jay Z

Posted on

Caution with try/expect when during with concurrent requests

Look at this code:
try
example.objects.get(name=xxx)
expect Exception:
example.objects.create(name=xxx)
blah, blah

The code seems to be working, but it is not thread safe. When we have concurrent requests coming to the server. The requests would penetrate into the expect block and try to create the resource or do something, causing unexpected behavior.

Top comments (0)