From f946083922e75f6081be535a284a0a0717b11b95 Mon Sep 17 00:00:00 2001 From: Aurelien Aptel Date: Thu, 16 Jul 2015 16:55:28 +0200 Subject: [PATCH] tdb python binding: raise KeyError(key) when the key doesn't exist This change makes tdb dicts more consistent with Python dicts. BUG: https://bugzilla.samba.org/show_bug.cgi?id=7416 Signed-off-by: Aurelien Aptel --- lib/tdb/pytdb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tdb/pytdb.c b/lib/tdb/pytdb.c index 9320799..1261bf5 100644 --- a/lib/tdb/pytdb.c +++ b/lib/tdb/pytdb.c @@ -598,7 +598,9 @@ static PyObject *obj_getitem(PyTdbObject *self, PyObject *key) val = tdb_fetch(self->ctx, tkey); if (val.dptr == NULL) { - PyErr_SetString(PyExc_KeyError, "No such TDB entry"); + /* if the key doesn't exist return KeyError(key) to be + consistent with python dict */ + PyErr_SetObject(PyExc_KeyError, key); return NULL; } else { return PyString_FromTDB_DATA(val); -- 2.1.4