@@ -261,7 +261,7 @@ def _to_tag_model_instances(self, tags, tag_kwargs):
261261 else : # above check for length of tag_strs avoids query here
262262 regex_string = r'(^' + '$|^' .join ([regex_escape (tag ) for tag in tag_strs ]) + '$)'
263263 existing = manager .filter (name__regex = regex_string )
264- tags_to_create = tag_strs - {t .name for t in existing }
264+ tags_to_create = set ( tag_strs ) - {t .name for t in existing }
265265 # we're going to end up doing this query anyways, so here is fine
266266 for t in existing :
267267 existing_tags_for_str [t .name ] = t
@@ -280,7 +280,7 @@ def _to_tag_model_instances(self, tags, tag_kwargs):
280280
281281 existing_tag = existing_tags_for_str .get (t , None )
282282 if existing_tag is None :
283- if existing_tag not in tags_to_create :
283+ if t not in tags_to_create :
284284 # should not happen
285285 raise ValueError (
286286 "Tag lookup failed for {}. This is likely a bug." .format (
@@ -292,7 +292,7 @@ def _to_tag_model_instances(self, tags, tag_kwargs):
292292 if case_insensitive :
293293 lookup = {"name__iexact" : t , ** tag_kwargs }
294294 else :
295- regex_string = r'(^' + regex_escape (new_tag ) + '$)'
295+ regex_string = r'(^' + regex_escape (t ) + '$)'
296296 lookup = {"name__regex" : regex_string , ** tag_kwargs }
297297 # lookup = {"name": t, **tag_kwargs}
298298 existing_tag , _ = manager .get_or_create (
0 commit comments