diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | psycopg/microprotocols.c | 4 | ||||
-rw-r--r-- | tests/types_extras.py | 9 |
3 files changed, 15 insertions, 1 deletions
@@ -1,5 +1,8 @@ 2009-11-25 Federico Di Gregorio <fog@initd.org> + * psycopg/microprotocols.c: "can't adapt" message now includes full + type information (adapted patch from Eric Chamberlain). + * tests/types_basic.py: fixed test broken by float precision fix. 2009-11-09 Federico Di Gregorio <fog@initd.org> diff --git a/psycopg/microprotocols.c b/psycopg/microprotocols.c index f451e7e..2499358 100644 --- a/psycopg/microprotocols.c +++ b/psycopg/microprotocols.c @@ -74,6 +74,7 @@ PyObject * microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) { PyObject *adapter, *key; + char buffer[256]; /* we don't check for exact type conformance as specified in PEP 246 because the ISQLQuote type is abstract and there is no way to get a @@ -114,7 +115,8 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) } /* else set the right exception and return NULL */ - psyco_set_error(ProgrammingError, NULL, "can't adapt", NULL, NULL); + PyOS_snprintf(buffer, 255, "can't adapt type '%s'", obj->ob_type->tp_name); + psyco_set_error(ProgrammingError, NULL, buffer, NULL, NULL); return NULL; } diff --git a/tests/types_extras.py b/tests/types_extras.py index 6cd55c1..98b1321 100644 --- a/tests/types_extras.py +++ b/tests/types_extras.py @@ -78,6 +78,15 @@ class TypesExtrasTests(unittest.TestCase): s = self.execute("SELECT NULL::inet AS foo") self.failUnless(s is None) + def test_adapt_fail(self): + class Foo(object): pass + self.assertRaises(psycopg2.ProgrammingError, + psycopg2.extensions.adapt, Foo(), psycopg2.extensions.ISQLQuote, None) + try: + psycopg2.extensions.adapt(Foo(), psycopg2.extensions.ISQLQuote, None) + except psycopg2.ProgrammingError, err: + self.failUnless(str(err) == "can't adapt type 'Foo'") + def test_suite(): return unittest.TestLoader().loadTestsFromName(__name__) |