If you perform more than one action on a new user, you get a "PDOException: SQLSTATE[23000]: Integrity constraint violation ... " in user_save() (... /modules/user/user.module)

Try it yourself:
Event - After saving a new user account
Action - Add user role
Action - Unblock a use (should be user?)

The above will cause an error, while having just one action won't.

Extra (similar) issues at: #1169800: [Integrity constraint violation: 1062 Duplicate entry] On user registration

Comments

SilviaT’s picture

Component: Rules Core » Rules Engine

Same issue for me.

fago’s picture

Title: Two adjustments on a new user cause a PDOException crash » Changing user after saving a new user cause a PDOException crash
Version: 7.x-2.0-beta2 » 7.x-2.x-dev

The bug will be triggered as soon as you add a role after user creation and something issues a user-save(). I don't think we can do anything about it except for fixing it in core.

kristiaanvandeneynde’s picture

So what does this mean for the issue itself?
Can it be fixed or do you suggest any sort of workaround?

Also: can't you create a queue system which only calls save_user() once (at the end of the queue) to prevent this issue?

altavis’s picture

subscribing

kristiaanvandeneynde’s picture

After some testing, I've come to the conclusion that this bug is most likely due to the code in either Rules or Entity, not core.
The way Rules handles the $account variable seems to cause this behaviour.

To "fix" the above issue, I've come up with the following four actions (instead of two):

  • Event - After saving a new user account
  • Action - Add user role
  • Action - Add a variable
    Parameter: Type: Integer, Value: [account:uid]
    Provides variables: The user id (the_user_id)
  • Action - Fetch entity by id
    Parameter: Entity type: User, Identifier: [the-user-id]
    Provides variables: The user (the_user)
  • Action - Unblock a user
    Parameter: User: [the-user]
  • Seeing as this kind of "resets" the user variable, it seems to me that Rules or Entity fail upon using the same variable multiple times.

    fago’s picture

    Status: Active » Closed (duplicate)
    pgancarski’s picture

    Component: Rules Engine » Rules Core

    Brilliant idea

    But not working when I try to apply a rule that edits a newly created Node.