Comment

Juan Margot

Seconding this comment. The Django ORM version should basically never be used in any real world situation. Very susceptible to race conditions.

Parent comment

Emmanuel Briot

The Django version is definitely worse: it has race conditions. If there are two threads (two queries) going through the code simultaneously , they might both end up trying to insert the object, and one of them will get an error. The SQL version does not have the issue. You mentioned this in a single sentence in the discussion, but this is a major win for the SQL version. The SQL version is bad, too, since it is subject to SQL injection. I am not sure what the proper way to do that with Django is, though.