Fix bug in tag querying. Resolve #2688.

This commit is contained in:
Griatch 2022-10-23 10:57:58 +02:00
parent 66e03d4a59
commit bf7f8e63c5
2 changed files with 19 additions and 0 deletions

View file

@ -197,6 +197,8 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
query.append(("db_key", key))
if category:
query.append(("db_category", category))
else:
query.append(("db_category", None))
return _Tag.objects.filter(**dict(query))
else:
# search only among tags stored on on this model

View file

@ -314,6 +314,23 @@ class TestTags(BaseEvenniaTest):
self.obj1.tags.add("tagC", "categoryC")
self.assertFalse(self.obj1.tags.has(category="categoryD"))
def test_tag_add_no_category__issue_2688(self):
"""
Adding a tag without a category should create a new tag:None tag
rather than trying to update an existing tag:category tag.
"""
# adding tag+category, creates tag+category entry
self.obj1.tags.add("testing", category="testing_category")
self.assertEqual(
self.obj1.tags.all(return_key_and_category=True), [("testing", "testing_category")]
)
# adding a new tag with no category should create a tag+None entry
self.obj1.tags.add("testing")
self.assertEqual(
self.obj1.tags.all(return_key_and_category=True),
[("testing", "testing_category"), ("testing", None)],
)
class TestNickHandler(BaseEvenniaTest):
"""