Problem with sequences using psycopg

Adam Ward <[email protected]> Fri, 10 Jun 2005 12:40:29 +1000
Newsgroups gmane.comp.web.skunkweb
Organization Managed Solutions
Message-ID <[email protected]>
When creating an object, and not specifying a sequence field, I get the
following error.

>>> user = User.new(name='adamw')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/pydo/base.py", line 402, in new
    return cls._new(fieldData, refetch)
  File "/usr/lib/python2.4/site-packages/pydo/base.py", line 428, in
_new
    fieldData[s] = conn.getSequence(sn)
  File "/usr/lib/python2.4/site-packages/pydo/drivers/psycopgconn.py",
line 145, in getSequence
    cur.execute(sql)
psycopg.ProgrammingError: relation "true" does not exist

where User is defined as:
class User(PyDO):
    connectionAlias = 'db'
    table = 'users'
    mutable = True
    refetch = True
    fields = (Sequence('id'),
              Unique('name'))

>From the postgresql log:
2005-06-10 12:16:04 [16251] LOG:  statement: BEGIN; SET TRANSACTION
ISOLATION LEVEL READ COMMITTED
2005-06-10 12:16:04 [16251] LOG:  statement: select nextval('True')
2005-06-10 12:16:04 [16251] ERROR:  relation "true" does not exist

I'm using:
>>> pydo.__version__
'2.0a3'
>>> psycopg.__version__
'2.0b3 (dt ext pq3)'

and tested it against both PostgreSQL 7.4 and 8.0

-------------

After a little bit of hacking around I tried:
class User(PyDO):
    connectionAlias = 'db'
    table = 'users'
    mutable = True
    refetch = True
    fields = (name='id', sequence='public.users_id_seq')

And it fixed the problem.

Shouldn't PyDO automatically find the sequence name for a given field?

Alternatively, this should be put on the new documentation page.


Thanks

-- 

Adam Ward



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20