Fixed #10472 -- Fixed a race condition in reverse URL resolving.

This only shows up in for reverse() (not forwards resolving), since that
path uses a globally shared resolver object. Based on a patch from
Travis Terry.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10037 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2009-03-12 07:28:22 +00:00
parent 6483fdf1fa
commit fb729cf1d9
2 changed files with 6 additions and 3 deletions

View File

@ -402,6 +402,7 @@ answer newbie questions, and generally made Django that much better:
Frank Tegtmeyer <fte@fte.to> Frank Tegtmeyer <fte@fte.to>
Marcel Telka <marcel@telka.sk> Marcel Telka <marcel@telka.sk>
Terry Huang <terryh.tp@gmail.com> Terry Huang <terryh.tp@gmail.com>
Travis Terry <tdterry7@gmail.com>
thebjorn <bp@datakortet.no> thebjorn <bp@datakortet.no>
Zach Thompson <zthompson47@gmail.com> Zach Thompson <zthompson47@gmail.com>
Michael Thornhill Michael Thornhill

View File

@ -154,6 +154,7 @@ class RegexURLResolver(object):
def _get_reverse_dict(self): def _get_reverse_dict(self):
if not self._reverse_dict: if not self._reverse_dict:
lookups = MultiValueDict()
for pattern in reversed(self.url_patterns): for pattern in reversed(self.url_patterns):
p_pattern = pattern.regex.pattern p_pattern = pattern.regex.pattern
if p_pattern.startswith('^'): if p_pattern.startswith('^'):
@ -165,11 +166,12 @@ class RegexURLResolver(object):
new_matches = [] new_matches = []
for piece, p_args in parent: for piece, p_args in parent:
new_matches.extend([(piece + suffix, p_args + args) for (suffix, args) in matches]) new_matches.extend([(piece + suffix, p_args + args) for (suffix, args) in matches])
self._reverse_dict.appendlist(name, (new_matches, p_pattern + pat)) lookups.appendlist(name, (new_matches, p_pattern + pat))
else: else:
bits = normalize(p_pattern) bits = normalize(p_pattern)
self._reverse_dict.appendlist(pattern.callback, (bits, p_pattern)) lookups.appendlist(pattern.callback, (bits, p_pattern))
self._reverse_dict.appendlist(pattern.name, (bits, p_pattern)) lookups.appendlist(pattern.name, (bits, p_pattern))
self._reverse_dict = lookups
return self._reverse_dict return self._reverse_dict
reverse_dict = property(_get_reverse_dict) reverse_dict = property(_get_reverse_dict)