Skip to content

Commit

Permalink
[Fixes #8984] Error adding remote services (#8985)
Browse files Browse the repository at this point in the history
  • Loading branch information
italogsfernandes authored Mar 28, 2022
1 parent ffaf018 commit 7804448
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def add(self, *tags, through_defaults=None, tag_kwargs=None):
if not isinstance(t, self.through.tag_model())
])
tag_objs = set(tags) - str_tags
new_ids = set()
# If str_tags has 0 elements Django actually optimizes that to not do a
# query. Malcolm is very smart.
'''
Expand All @@ -471,14 +472,11 @@ def add(self, *tags, through_defaults=None, tag_kwargs=None):
we can easily handle the concurrency.
DOC: https://docs.djangoproject.com/en/3.2/ref/models/querysets/#select-for-update
'''
existing = self.through.tag_model().objects.select_for_update().filter(
name__in=str_tags, **tag_kwargs
)
tag_objs.update(existing)
new_ids = set()
with transaction.atomic():
existing = self.through.tag_model().objects.select_for_update().filter(
name__in=str_tags, **tag_kwargs
)
tag_objs.update(existing)
new_ids = set()
_new_keyword = str_tags - set(t.name for t in existing)
for new_tag in list(_new_keyword):
new_tag = escape(new_tag)
Expand Down

0 comments on commit 7804448

Please sign in to comment.