Re: problem with copy_expert on cursor

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Eric Snow <esnow(at)verio(dot)net>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: problem with copy_expert on cursor
Date: 2011-03-03 00:23:13
Message-ID: AANLkTin_AUSkU80cah-2xM9LOrxe=6ihJQd1CR=UgCC6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Wed, Mar 2, 2011 at 9:20 PM, Eric Snow <esnow(at)verio(dot)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())

In response to

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2011-03-03 00:28:44 Re: problem with copy_expert on cursor
Previous Message Eric Snow 2011-03-02 23:19:20 Re: problem with copy_expert on cursor