Fixed a bug in obj_from_dbid (obj_from_dbref). Resolves #980.
This commit is contained in:
parent
410d04456c
commit
730d08e790
1 changed files with 8 additions and 5 deletions
|
|
@ -462,12 +462,12 @@ def dbref(dbref, reqhash=True):
|
||||||
return dbref if isinstance(dbref, int) else None
|
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:
|
Args:
|
||||||
inp (str or int): A valid dbref.
|
inp (str or int): A valid #dbref.
|
||||||
objclass (class): A valid django model to filter against.
|
objclass (class): A valid django model to filter against.
|
||||||
raise_errors (bool, optional): Whether to raise errors
|
raise_errors (bool, optional): Whether to raise errors
|
||||||
or return `None` on errors.
|
or return `None` on errors.
|
||||||
|
|
@ -486,19 +486,22 @@ def dbid_to_obj(inp, objclass, raise_errors=True):
|
||||||
# we only convert #dbrefs
|
# we only convert #dbrefs
|
||||||
return inp
|
return inp
|
||||||
try:
|
try:
|
||||||
if int(inp) < 0:
|
if dbid < 0:
|
||||||
return None
|
return None
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# if we get to this point, inp is an integer dbref; get the matching object
|
# if we get to this point, inp is an integer dbref; get the matching object
|
||||||
try:
|
try:
|
||||||
return objclass.objects.get(id=inp)
|
return objclass.objects.get(id=dbid)
|
||||||
except Exception:
|
except Exception:
|
||||||
if raise_errors:
|
if raise_errors:
|
||||||
raise
|
raise
|
||||||
return inp
|
return inp
|
||||||
|
|
||||||
|
# legacy alias
|
||||||
|
dbid_to_obj = dbref_to_obj
|
||||||
|
|
||||||
|
|
||||||
def to_unicode(obj, encoding='utf-8', force_string=False):
|
def to_unicode(obj, encoding='utf-8', force_string=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue