-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAEBCAAGBQJVTNs3AAoJEC0ft5FqUuEhT9IP/AsxVRIHlAE6JB/blkNa05rK
omvWjnl2Vgar+USgzuSObvyU7X7Hn8nLTu3/Z5JB6NyKCbnW1hr0Poh3p6rOs+9p
tMdCdfKFe6cmO9twjXIgCgh4ICCEOA1SRkr0LpJTyHMg2KISm4lDWz7CCdB0QNou
Z6jQFajtYZd6UYj0MKcS98fmnuoGNlfgrqM92NWo6bptXg37lKrYiQQSVOBX0ZDF
35v6BR7wpE1qm6vOwlR/VoeQ7zX764YjikW0KGwVZaJP7fseRBHBV2rqn8xDO0+A
EP+ey113JHMv7YhO0Do5mjD3RfweI/9cWPOpjgMOj4DWdMX0JpE/k0h+WZC2z325
d8U0lalkFiiwaWiUyOoEP/PY9bSSq6fQdyjz9h0nDyzUZsIQ/zI6jvHP3XfEDfxN
W2QEZ7BWBJr0+QZktyjXD5XyRxerBZx+bPaMsTmRbLB+i1xXngRKfao5J7TWaXX4
S+MyHv2IQUQmYkvToXuQgas9FyFc8xBd/6qZLTxl0mmGQuaiQCtSwnnJDzAIR9Zw
b84xrF4u1fsuRiwFZfm+osiW8RoKinC5XVV0/h7JUEhdqhzj9tf9oyaskpH0U3qb
XBpJ2BzBm2fpkZ9aTQubnZpnD9JM/d/DMmz1h0y1oR9xwSK2oD5D1u0DGIwCUOwC
Ei2X5glo3ws8bMGZ4uhZ
=UkGw
-----END PGP SIGNATURE-----
Hi Marc,
On 05/08/2015 07:15 AM, Marc Aymerich wrote:
> I'm using atomic requests, but one of my views needs to save a model
> regardless of wheter the current transaction rolls back or not.
>
> I'm confused about how to proceed with the current autocommit behaviour.
> Do I need to use a different db connection? or perhaps there is some way
> of telling django to ignore autocommit for some particular block ?
You'd need to use a different db connection, since what you're trying to
do violates the very nature of a database transaction. If you were just
trying to run some raw SQL, you could establish the separate connection
yourself manually, but if you're trying to save a Django model, you'll
probably need a second connection defined in your DATABASES setting.
Possible alternatives:
- If you're using a task queuing system (like Celery or rq), queue a
task to perform the save; you can do this without making it conditional
on the transaction committing, as long as your task queue is using a
store other than your primary database (e.g. Redis or RabbitMQ). Usually
when people do this it's unintentional and a bug (they really wanted the
task to execute only if the current transaction committed), but in your
case it could be a feature.
- Switch from ATOMIC_REQUESTS to explicit use of transaction.atomic() in
your views, so that you can place this "no matter what" save in its own
transaction.
Carl
--
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/554CDB37.7060503%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment