From b86df6e47c85fd50125cc99bce6dba0e27650840 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 Reviewed-by: Andrew Bartlett Reviewed-by: Stefan Metzmacher --- lib/tdb/pytdb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/tdb/pytdb.c b/lib/tdb/pytdb.c index b0f9cd961d7..c9d3a7660e3 100644 --- a/lib/tdb/pytdb.c +++ b/lib/tdb/pytdb.c @@ -650,7 +650,11 @@ 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 raise KeyError(key) to be + * consistent with python dict + */ + PyErr_SetObject(PyExc_KeyError, key); return NULL; } else { return PyBytes_FromTDB_DATA(val); -- 2.11.4.GIT