From 21a52859541ca27d8d9a612d04eaeeb7e84f7adc Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 8 Jun 2019 17:34:30 +0200 Subject: [PATCH] Make sure to avoid double multi-matches from rpsystem. Resolve #1757 --- evennia/contrib/rpsystem.py | 25 ++++++++++++++----------- evennia/objects/manager.py | 4 ++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/evennia/contrib/rpsystem.py b/evennia/contrib/rpsystem.py index 5d1957bea5..9b9a8daab3 100644 --- a/evennia/contrib/rpsystem.py +++ b/evennia/contrib/rpsystem.py @@ -1268,16 +1268,19 @@ class ContribRPObject(DefaultObject): is_builder = self.locks.check_lockstring(self, "perm(Builder)") use_dbref = is_builder if use_dbref is None else use_dbref - def search_obj(string): return ObjectDB.objects.object_search(string, - attribute_name=attribute_name, - typeclass=typeclass, - candidates=candidates, - exact=exact, - use_dbref=use_dbref) + def search_obj(string): + "helper wrapper for searching" + return ObjectDB.objects.object_search(string, + attribute_name=attribute_name, + typeclass=typeclass, + candidates=candidates, + exact=exact, + use_dbref=use_dbref) if candidates: candidates = parse_sdescs_and_recogs(self, candidates, - _PREFIX + searchdata, search_mode=True) + _PREFIX + searchdata, + search_mode=True) results = [] for candidate in candidates: # we search by candidate keys here; this allows full error @@ -1285,7 +1288,8 @@ class ContribRPObject(DefaultObject): # in eventual error reporting later (not their keys). Doing # it like this e.g. allows for use of the typeclass kwarg # limiter. - results.extend(search_obj(candidate.key)) + results.extend([obj for obj in search_obj(candidate.key) + if obj not in results]) if not results and is_builder: # builders get a chance to search only by key+alias @@ -1299,7 +1303,8 @@ class ContribRPObject(DefaultObject): if quiet: return results return _AT_SEARCH_RESULT(results, self, query=searchdata, - nofound_string=nofound_string, multimatch_string=multimatch_string) + nofound_string=nofound_string, + multimatch_string=multimatch_string) def get_display_name(self, looker, **kwargs): """ @@ -1497,5 +1502,3 @@ class ContribRPCharacter(DefaultCharacter, ContribRPObject): """ return "%s|w%s|n" % ("|W(%s)" % language if language else "", text) - #from evennia.contrib import rplanguage - # return "|w%s|n" % rplanguage.obfuscate_language(text, level=1.0) diff --git a/evennia/objects/manager.py b/evennia/objects/manager.py index 1b39d33e5a..3469da934b 100644 --- a/evennia/objects/manager.py +++ b/evennia/objects/manager.py @@ -265,9 +265,9 @@ class ObjectDBManager(TypedObjectManager): type_restriction = typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q() if exact: # exact match - do direct search - return self.filter(cand_restriction & type_restriction & ( + return (self.filter(cand_restriction & type_restriction & ( Q(db_key__iexact=ostring) | Q(db_tags__db_key__iexact=ostring) & Q( - db_tags__db_tagtype__iexact="alias"))).order_by('id').distinct() + db_tags__db_tagtype__iexact="alias")))).distinct().order_by('id') elif candidates: # fuzzy with candidates search_candidates = self.filter(cand_restriction & type_restriction).distinct().order_by('id')