svc/connect.in (Peer.get): Don't apply filter to default value.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 11 Jun 2018 12:00:07 +0000 (13:00 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 14 Jun 2018 11:50:38 +0000 (12:50 +0100)
Callers don't expect this, and there will be unfortunate behaviour.  For
example, `T.timespec' explodes if handed a literal integer rather than a
string.

svc/connect.in

index 607a656..7a93572 100644 (file)
@@ -296,12 +296,15 @@ class Peer (object):
     a FILTER function is given then apply it to the information from the
     database before returning it.
     """
-    attr = me.__dict__.get(key, default)
-    if attr is _magic:
-      raise T.TripeJobError('malformed-peer', me.name, 'missing-key', key)
-    elif filter is not None:
-      attr = filter(attr)
-    return attr
+    try:
+      attr = me.__dict__[key]
+    except KeyError:
+      if default is _magic:
+        raise T.TripeJobError('malformed-peer', me.name, 'missing-key', key)
+      return default
+    else:
+      if filter is not None: attr = filter(attr)
+      return attr
 
   def has(me, key):
     """