-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAEBCAAGBQJVguiQAAoJEC0ft5FqUuEhX9QP/iA5YSuRD8amajl9ZSyg6GZD
X+xeWuePggn8B9wdv2yIdBz87FIY6HCjLt6VgxXODDy8tq89H2zTA1NfGOTNEwi1
/xSTtDyto43WaIpXmy1BE6qqIYbzZEzDGc0NYydUUxqnN0ij3OCfTeaStuhOAYQO
eObiRMo6GuvgYTY30pJ2V5hmVyFONZykygmvPbjXGOQaqgKbg5llT+GbCWDb/v+i
bktpX31kC7NlkaqYBnHTjhiAE7wHjzKryaS/YHrapX8OuEq34G8oPjZgELvHrurI
tnSBsfYcu5RHNngNt7fgAYa2/4/CGpLGj9QuydVHiIa4/lloHDN8/LC4ZkI0X6xd
QeEFnd4pQUdcXB5PhO/dbkSR+pzzWTGDbloAu8gxAczjDLPjCxitX3K0dN/C4h8w
YrucLbA7rRaiu+sgkZSpBWNVyRs7qqOS9jP0Zl1ldMlvsCs+K7f/imM2ejqyJ7Fc
xmnGHLLDxay4oj1ah0wCqsJGv0ZUbaZOjGijgo926Y+UzQO9GRqTFBvwN6wjaDSn
itfsrL6qjSpfqMW2EN7uMhqvBaxJKEya2H4CWJ+lrWFouKZzcgutKu916YahsUPt
LXka5mUA3yOAFzSsFlXj7zz7ATqi1mRoJXAgAGOr01mZp28VjTdisiVOs0DRMCFH
yRzLTDYKraLebeLjuGfe
=L32o
-----END PGP SIGNATURE-----
Hi Kate,
On 06/18/2015 04:05 AM, Katarzyna Łabędź wrote:
> Maybe i didn't understand it correctly.
>
> I know Django support transactions, but isn't it do it on commit?
> I just tried to find the BEGIN statement inside them and i could not
> find it - searched through internet and what I found was a bunch of
> people asking the same question - where is the begin in the
> transactions? So i just figured i ask here.
> Why Django don't execute Begin statement ? Isn't it necessary to have a
> fully correct transaction?
You are right to be confused, because this is confusing territory.
The default behavior of all Python database adapters is "implicit
transactions", meaning the underlying database adapter library itself
(Python-MySQL, psycopg2, etc) sends a BEGIN automatically as soon as you
send your first query. (At least if the library is compliant with PEP
249 [1], the Python database adapter standard, which all adapters used
by built-in Django backends are.)
Django overrides this and places the underlying connection into
autocommit mode (no transactions) by default. But when you request a
transaction (by using an 'atomic' block), Django doesn't need to
explicitly send BEGIN, it just puts the connection back into the default
PEP 249 "implicit transactions" mode, which means the database adapter
will send BEGIN automatically as soon as you send a query. So Django
never sends a BEGIN itself, just COMMIT or ROLLBACK.
In practice, though, you can ignore this implementation detail, and just
assume that a BEGIN is sent at the start of any (outer) 'atomic' block
(and COMMIT or ROLLBACK) is sent at the end, and you'll be correct.
I wrote a blog post [2] which discusses this in more detail. It's about
PostgreSQL instead of MySQL, but the part near the beginning about PEP
249 and Django applies equally well to MySQL (I think; I'm not very
familiar with transactions on MySQL).
Carl
[1] https://www.python.org/dev/peps/pep-0249/
[2] http://oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5582E88F.7090709%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment