From: Mark Wooding Date: Mon, 11 Jun 2018 12:00:07 +0000 (+0100) Subject: svc/connect.in (Peer.get): Don't apply filter to default value. X-Git-Tag: 1.5.0~62 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/c7737d905aad7a2aaf523b1444f2b69a0088402a?ds=sidebyside svc/connect.in (Peer.get): Don't apply filter to default value. 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. --- diff --git a/svc/connect.in b/svc/connect.in index 607a6561..7a935723 100644 --- a/svc/connect.in +++ b/svc/connect.in @@ -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): """