Re: problem with copy_expert on cursor - Mailing list psycopg

From Daniele Varrazzo
Subject Re: problem with copy_expert on cursor
Date
Msg-id AANLkTin_AUSkU80cah-2xM9LOrxe=6ihJQd1CR=UgCC6@mail.gmail.com
Whole thread Raw
In response to problem with copy_expert on cursor  ("Eric Snow" <esnow@verio.net>)
List psycopg
On Wed, Mar 2, 2011 at 9:20 PM, Eric Snow <esnow@verio.net> wrote:
> What would cause the following error when I call copy_expert on a
> DictCursor?
>
>    SystemError: 'null argument to internal routine'
>
> The sql I pass in is the copy, in a string.  The file is a
> cStringIO.StringO object.  I am using a custom row factory on the
> DictCursor.  So there are a number of things that could be the source of
> the error.  However, I am not familiar enough with psycopg to dig this
> out.
>
> Incidently, the problem is actually when I am using skytools for
> replication, and not actually in any code I have written.  I am using
> psycopg2 2.3.2.  Thanks.

Hi Eric,

the description of the problem is not very clear, e.g. I've not
understood if the problem happened in a COPY FROM STDIN or in COPY TO
STDOUT. I've tried to reproduce the problem but without success, both
in 2.3.2 and in 2.4.0.

To try and reproduce the problem I've added the test below to
tests/test_copy.py. Can you modify the test until you are able to make
it crash?

In order to run the test suite, create a database called
"psycopg2_test". Then, from the psycopg directory, execute "make",
then "make check". If you need to specify host/username/password to
connect to the database, set the env variables PSYCOPG2_TESTDB_HOST
and so on.

Thank you.

-- Daniele

    def test_copy_strange_cursor(self):
        from psycopg2.extras import DictCursor
        f = StringIO()
        for i, c in enumerate(string.ascii_letters):
            f.write("%s\t%s\n" % (i, c))

        f.seek(0)

        curs = self.conn.cursor(cursor_factory=DictCursor)
        curs.copy_expert('COPY tcopy FROM STDIN', f)
        curs.close()

        curs = self.conn.cursor()
        curs.execute("select * from tcopy order by id;")
        self.assertEqual(curs.fetchall(),
            list(enumerate(string.ascii_letters)))

        f1 = StringIO()
        curs = self.conn.cursor(cursor_factory=DictCursor)
        curs.copy_expert('COPY tcopy TO STDOUT', f1)
        curs.close()

        f.seek(0)
        f1.seek(0)
        self.assertEqual(f1.read(), f.read())

psycopg by date:

Previous
From: "Eric Snow"
Date:
Subject: Re: problem with copy_expert on cursor
Next
From: Daniele Varrazzo
Date:
Subject: Re: problem with copy_expert on cursor