Commit c8257843 by Florian Apolloner

Merge pull request #201 from apollo13/atomic

Use Django's atomic when available.
parents a0b63448 d6117ab9
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
env:
- DJANGO=https://github.com/django/django/archive/master.tar.gz
- DJANGO=django==1.6
- DJANGO=django==1.5.5
- DJANGO=django==1.4.10
- TOXENV=py27-1.7.x
- TOXENV=py33-1.5.x
- TOXENV=py27-1.6.x
- TOXENV=py33-1.6.x
- TOXENV=py26-1.6.x
- TOXENV=py27-1.5.x
- TOXENV=py27-1.4.x
- TOXENV=py33-1.7.x
- TOXENV=py26-1.4.x
- TOXENV=py26-1.5.x
install:
- pip install $DJANGO
- pip install -r requirements/travis-ci.txt --use-mirrors
- pip install tox
script:
- coverage run --source django_taggit runtests.py
- coverage report
- tox
notifications:
email: false
matrix:
exclude:
- python: "3.2"
env: DJANGO=django==1.4.10
- python: "3.3"
env: DJANGO=django==1.4.10
- python: "2.6"
env: DJANGO=https://github.com/django/django/archive/master.tar.gz
......@@ -9,6 +9,23 @@ from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils.encoding import python_2_unicode_compatible
try:
atomic = transaction.atomic
except AttributeError:
from contextlib import contextmanager
@contextmanager
def atomic(using=None):
sid = transaction.savepoint(using=using)
try:
yield
except IntegrityError:
transaction.savepoint_rollback(sid, using=using)
raise
else:
transaction.savepoint_commit(sid, using=using)
@python_2_unicode_compatible
class TagBase(models.Model):
name = models.CharField(verbose_name=_('Name'), unique=True, max_length=100)
......@@ -30,17 +47,14 @@ class TagBase(models.Model):
# with a multi-master setup, theoretically we could try to
# write and rollback on different DBs
kwargs["using"] = using
trans_kwargs = {"using": using}
i = 0
while True:
i += 1
try:
sid = transaction.savepoint(**trans_kwargs)
res = super(TagBase, self).save(*args, **kwargs)
transaction.savepoint_commit(sid, **trans_kwargs)
with atomic(using=using):
res = super(TagBase, self).save(*args, **kwargs)
return res
except IntegrityError:
transaction.savepoint_rollback(sid, **trans_kwargs)
self.slug = self.slugify(self.name, i)
else:
return super(TagBase, self).save(*args, **kwargs)
......
......@@ -58,24 +58,6 @@ deps =
{[testenv]deps}
{[testenv]deps17}
[testenv:py32-1.5.x]
basepython = python3.2
deps =
{[testenv]deps}
{[testenv]deps15}
[testenv:py32-1.6.x]
basepython = python3.2
deps =
{[testenv]deps}
{[testenv]deps16}
[testenv:py32-1.7.x]
basepython = python3.2
deps =
{[testenv]deps}
{[testenv]deps17}
[testenv:py33-1.5.x]
basepython = python3.3
deps =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment