<p>答案就在拐角处,在<a href="https://docs.djangoproject.com/en/dev/topics/db/transactions/#select-for-update" rel="nofollow">select_for_update</a>(emphasis mine)的文档中:</p>
<blockquote>
<p>Evaluating a queryset with select_for_update in autocommit mode is an
error because the rows are then not locked. If allowed, <strong>this would
facilitate data corruption,</strong> and could easily be caused by calling,
outside of any transaction, code that expects to be run in one.</p>
</blockquote>
<p>换句话说,在<code>autocommit</code>和{<cd2>}之间存在矛盾的行为,这可能导致数据损坏。这里是他们第一次提出解决这个问题的<a href="https://groups.google.com/forum/#!topic/django-developers/8woZjCPcFmA" rel="nofollow">django developer's discussion</a>,引用(同样,强调我的):</p>
<blockquote>
<p>[...] under Oracle, in autocommit mode, the automatic commit happens
immediately after the command is executed and so, trying to fetch
the results fails for being done in a separate transaction. </p>
<p>However, <strong>with any backend, select-for-update in autocommit mode
makes very little sense. Even if it doesn't break (as it does on
Oracle), it doesn't really lock anything.</strong> So, IMO, executing a
query that is a select-for-update in autocommit mode is probably en
error, and one that is likely to cause data- corruption bugs. </p>
<p>So I'm suggesting we change the behavior of select-for-update queries,
to error out [...] This is a backwards-incompatible change [...]
These projects should probably be thankful they were running with a
subtle bug that is now exposed but still.</p>
</blockquote>
<p>所以这是一个只有Oracle的bug,它揭示了一个与所有后端相关的更深层次的问题,所以他们决定在django中把这个错误作为一个错误。在</p>
<p>另一方面,<code>Atomic</code>只在数据库验证没有错误后才将内容提交给数据库,从而解决了问题。在</p>