(Real)DictConnection is not compatible with the adaptation mechanism

Lawrence Oluyede <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
I tried to register an adapter for a SQL type following the examples
and the documentation and it all worked fine.
My problem manifested itself when I tried to integrate the code with
the real application which uses (Real)DictConnection.

When I register the new type with:

psycopg2.extensions.register_type(NEWTYPE, conn)

it breaks with the following error:

TypeError: argument 2 must be a connection, cursor or None

which is located in psycopgmodule.c in function psyco_register_type.

It seems that it checks for "cursorType" and "connectionType"
preventing inherited objects to work with the adaptation mechanism:

psyco_register_type(PyObject *self, PyObject *args)
{
   [...]

    if (obj != NULL) {
        if (obj->ob_type == &cursorType) {
            _psyco_register_type_set(&(((cursorObject*)obj)->string_types),
type);
        }
        else if (obj->ob_type == &connectionType) {
            typecast_add(type, ((connectionObject*)obj)->string_types, 0);
        }
        else {
            PyErr_SetString(PyExc_TypeError,
                "argument 2 must be a connection, cursor or None");
            return NULL;
        }
    }

  [..]

Is there a way to work around it?

-- 
Lawrence, http://oluyede.org - http://twitter.com/lawrenceoluyede
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.