On Sunday 22 September 2013 10:38:32 Anssi Kääriäinen wrote:
>
> I would go for an approach where all queries in marked-for-rollback block
> are prevented. See https://github.com/akaariai/django/compare/ticket_21134
>
> Note that this is the test case I am complaining about:
>
> r1 = Reporter.objects.create(first_name='foo', last_name='bar')
> with transaction.atomic():
> r2 = Reporter(first_name='foo', last_name='bar2', id=r1.id)
> try:
> r2.save(force_insert=True)
> except IntegrityError:
> r2.save(force_update=True)
> self.assertEqual(Reporter.objects.get(pk=r1.pk).last_name, 'bar2')
>
> The last assert currently fails. There is no explicit use of
> savepoint=False. It is reasonable to expect that the code succeeds on
> databases that allow this coding pattern. So, as is, this API is bad.
>
> If running read-only queries in marked-for-rollback blocks is absolutely
> wanted, then lets just switch model.save() and other similar ORM operations
> to use real savepoints. This is expensive for some use cases, but adding a
> flag to avoid that cost can be done later on. The tx API is harder to
> change after 1.6 release.
>
Maybe I'm a little too late to this party, but for all non-postgresql users,
this behavior (both current and Anssi's suggestion) would be very surprising.
I would take Anssi's suggestion another step forward -- or backward, depends
where you're looking from :-) -- stop marking transactions for rollback. Make
save() and associates use savepoints, only on PostgreSQL, so that, everywhere,
one may recover from database errors within the transaction.
Then, as Anssi suggests, we can use a flag to remove these savepoints for
performance when correctness has been established.
(I am intimately familiar with a large code base that is full of such recovery
attempts, mainly because PostgreSQL has never been a primary target; on
Sqlite, Oracle and SQL Server, these things work fine. I'm sure the case I know
isn't the only one).
My 2 cents,
Shai.
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.