From 730d08e790143d6c0d09c3e9420e1fce7c89ac59 Mon Sep 17 00:00:00 2001 From: Griatch Date: Wed, 1 Jun 2016 23:09:33 +0200 Subject: [PATCH] Fixed a bug in obj_from_dbid (obj_from_dbref). Resolves #980. --- evennia/utils/utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index 3b7a050a7..3c81c8378 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -462,12 +462,12 @@ def dbref(dbref, reqhash=True): return dbref if isinstance(dbref, int) else None -def dbid_to_obj(inp, objclass, raise_errors=True): +def dbref_to_obj(inp, objclass, raise_errors=True): """ - Convert a #dbid to a valid object. + Convert a #dbref to a valid object. Args: - inp (str or int): A valid dbref. + inp (str or int): A valid #dbref. objclass (class): A valid django model to filter against. raise_errors (bool, optional): Whether to raise errors or return `None` on errors. @@ -486,19 +486,22 @@ def dbid_to_obj(inp, objclass, raise_errors=True): # we only convert #dbrefs return inp try: - if int(inp) < 0: + if dbid < 0: return None except ValueError: return None # if we get to this point, inp is an integer dbref; get the matching object try: - return objclass.objects.get(id=inp) + return objclass.objects.get(id=dbid) except Exception: if raise_errors: raise return inp +# legacy alias +dbid_to_obj = dbref_to_obj + def to_unicode(obj, encoding='utf-8', force_string=False): """