Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-taggit
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
92d4cbe1
authored
Mar 01, 2014
by
Florian Apolloner
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #202 from apollo13/atomic2
Prevented infinite loops on Tag.save()
parents
0e9f1172
b32c6cbe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
7 deletions
+18
-7
taggit/models.py
+18
-7
No files found.
taggit/models.py
View file @
92d4cbe1
...
...
@@ -47,15 +47,26 @@ class TagBase(models.Model):
# with a multi-master setup, theoretically we could try to
# write and rollback on different DBs
kwargs
[
"using"
]
=
using
i
=
0
# Be oportunistic and try to save the tag, this should work for
# most cases ;)
try
:
with
atomic
(
using
=
using
):
res
=
super
(
TagBase
,
self
)
.
save
(
*
args
,
**
kwargs
)
return
res
except
IntegrityError
:
pass
# Now try to find existing slugs with similar names
slugs
=
set
(
Tag
.
objects
.
filter
(
slug__startswith
=
self
.
slug
)
\
.
values_list
(
'slug'
,
flat
=
True
))
i
=
1
while
True
:
slug
=
self
.
slugify
(
self
.
name
,
i
)
if
slug
not
in
slugs
:
self
.
slug
=
slug
# We purposely ignore concurrecny issues here for now.
# (That is, till we found a nice solution...)
return
super
(
TagBase
,
self
)
.
save
(
*
args
,
**
kwargs
)
i
+=
1
try
:
with
atomic
(
using
=
using
):
res
=
super
(
TagBase
,
self
)
.
save
(
*
args
,
**
kwargs
)
return
res
except
IntegrityError
:
self
.
slug
=
self
.
slugify
(
self
.
name
,
i
)
else
:
return
super
(
TagBase
,
self
)
.
save
(
*
args
,
**
kwargs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment