summaryrefslogtreecommitdiff
path: root/psycopg
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-05 11:54:50 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-05 11:54:50 +0100
commit3fbff5d8484099b46aebc499ffaa2a745e510f09 (patch)
tree02d41e96dbf4b6bba67be71462229d3e66b3a384 /psycopg
parent9863637f309e1e89523007c40e9dcdde69f60bc0 (diff)
downloadpsycopg2-3fbff5d8484099b46aebc499ffaa2a745e510f09.tar.gz
Give precedence to '__conform__()' over superclasses choosing adapter
Close #456
Diffstat (limited to 'psycopg')
-rw-r--r--psycopg/microprotocols.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/psycopg/microprotocols.c b/psycopg/microprotocols.c
index 3ddcc48..0e74cee 100644
--- a/psycopg/microprotocols.c
+++ b/psycopg/microprotocols.c
@@ -153,15 +153,6 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
return adapted;
}
- /* Check if a superclass can be adapted and use the same adapter. */
- if (!(adapter = _get_superclass_adapter(obj, proto))) {
- return NULL;
- }
- if (Py_None != adapter) {
- adapted = PyObject_CallFunctionObjArgs(adapter, obj, NULL);
- return adapted;
- }
-
/* try to have the protocol adapt this object*/
if ((meth = PyObject_GetAttrString(proto, "__adapt__"))) {
adapted = PyObject_CallFunctionObjArgs(meth, obj, NULL);
@@ -181,7 +172,7 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
PyErr_Clear();
}
- /* and finally try to have the object adapt itself */
+ /* then try to have the object adapt itself */
if ((meth = PyObject_GetAttrString(obj, "__conform__"))) {
adapted = PyObject_CallFunctionObjArgs(meth, proto, NULL);
Py_DECREF(meth);
@@ -200,6 +191,15 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
PyErr_Clear();
}
+ /* Finally check if a superclass can be adapted and use the same adapter. */
+ if (!(adapter = _get_superclass_adapter(obj, proto))) {
+ return NULL;
+ }
+ if (Py_None != adapter) {
+ adapted = PyObject_CallFunctionObjArgs(adapter, obj, NULL);
+ return adapted;
+ }
+
/* else set the right exception and return NULL */
PyOS_snprintf(buffer, 255, "can't adapt type '%s'",
Py_TYPE(obj)->tp_name);