mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
Now adapt() errors include the type name
This commit is contained in:
parent
d40a5321f2
commit
bcc836c661
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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__)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user