Modify

Opened 18 years ago

Closed 8 years ago

Last modified 8 years ago

#1504 closed defect (wontfix)

get_last_id() causing an error and sequence question

Reported by: brian@… Owned by: Anton Stroganov
Priority: normal Component: MantisImportScript
Severity: critical Keywords: currval, seqence
Cc: Trac Release: 0.10

Description

This line was giving me an error.

return self.db().get_last_id(c,'ticket')

psycopg2.ProgrammingError: currval of sequence "ticket_id_seq" is not yet defined in this session

This seems utterly wrong to me since i can select currval('ticket_id_seq') via psql. It's not used so i commented it out.

On a slightly different note, are the sequences in postgresql set correctly after all tickets, comments, stuff are inserted?

Attachments (0)

Change History (2)

comment:1 Changed 15 years ago by Scott

I ran into this as well.

The problem is that currval of a sequence id is a a session-local value. It cannot be retrieved unless nextval has been called for the current session.

I fixed this by modifying: /usr/lib/python2.6/dist-packages/trac/db/postgres_backend.py

to call setval, max(id) first to update the sequence value for the session

+++ /usr/lib/python2.6/dist-packages/trac/db/postgres_backend.py
@@ -215,5 +215,6 @@
         return _like_escape_re.sub(r'/\1', text)
 
     def get_last_id(self, cursor, table, column='id'):
+ cursor.execute("SELECT SETVAL('%s_%s_seq', max(%s)) FROM %s" % (table, column,column,table))
         cursor.execute("SELECT CURRVAL('%s_%s_seq')" % (table, column))
         return cursor.fetchone()[0] 
Last edited 8 years ago by Ryan J Ollos (previous) (diff)

comment:2 Changed 8 years ago by Ryan J Ollos

Resolution: wontfix
Status: newclosed

New version of plugin is on GitHub. Please open a new ticket if you have an issue with the new version.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Anton Stroganov.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.