When I want to create user, I'm getting an error:

PDOException: SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR: currval of sequence "subscriptions_sid_seq" is not yet defined in this session: INSERT INTO subscriptions (module, field, value, send_interval, author_uid, send_updates, send_comments, recipient_uid) SELECT s.module AS module, s.field AS field, s.value AS value, s.send_interval AS send_interval, s.author_uid AS author_uid, s.send_updates AS send_updates, s.send_comments AS send_comments, 94 AS recipient_uid FROM subscriptions s WHERE (s.recipient_uid IN (:db_condition_placeholder_0)) ; Array ( ) v subscriptions_user_insert() (riadok 336 z .....modules/subscriptions/subscriptions.module).

I'm using Drupal 7.15, last dev version of Subscriptions.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

salvis’s picture

Title: Can't create user - subscriptions module error on PostgreSQL » PostgreSQL: "Object not in prerequisite state" error when trying to create a user
Priority: Critical » Normal

PostgreSQL quirks are not critical.

Any PostgreSQL gurus out there?

salvis’s picture

Status: Active » Postponed (maintainer needs more info)

Sorry, no one seems to know how to fix this.

salvis’s picture

Issue tags: +PostgreSQL

Similar pgsql issues:
#1815158: PostgreSQL & MS SQL Server: PDO error on forum administration interface first access
#1320148: Install error on PostgreSQL

According to the PostgreSQL documentation, the subselect returning nothing should not be a problem.

I've tried listing the ->fields() and I've tried ->useDefaults(), both without success (resulting in MySQL errors).

ecomundo’s picture

We have the same issue here. Many of the admin actions returns the error : PDOException: SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR: currval of sequence "sequence_name" is not yet defined in this session.

According to our research, the currval function return the last nextval executed with the active database session. The lastval function returning the last nexval for all database session. So both of this functions are not define if no nextval has been executed.

salvis’s picture

Subscriptions does not deal with currval/nextval/etc. at all. Apparently, this happens in the database layer, but I have no idea why and what for.

karleberts’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
439 bytes

The problem seems to be when a new user is created the subselect returns nothing, so the insert doesn't actually insert anything either. By default, db_insert returns the id of the row by calling PDO::lastInsertId (which seems to just call currval() on the sequence), hence the error when nothing is inserted.

Modifying the options to db_insert to not return the id allows this step to be skipped; the return value for the insert isn't used anyway.

Status: Needs review » Needs work

The last submitted patch, 1807356-6-user-insert-query.patch, failed testing.

karleberts’s picture

Submitted patch in the wrong format. This should be better.

salvis’s picture

Status: Needs work » Needs review

Oh, great, thank you for the analysis and patch.

Can someone else on pgsql confirm that this fixes the problem?

jweowu’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed.

This is clearly a bug in the database layer, but I believe this patch is the cleanest workaround.

salvis’s picture

Status: Reviewed & tested by the community » Fixed

Great, thanks karleberts and jweowu!

Pushed to the -dev version.

Automatically closed -- issue fixed for 2 weeks with no activity.