The hook Update throws below error

[error] SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4-openid_connect.myProvider' for key 'PRIMARY': INSERT INTO {authmap} (uid, provider, authname) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2);

When there are multiple records in old openid_connect table openid_connect_authmap

Proposed Solution:
Include the login in try and catch block to bypass the hook update fail scenario

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rakshith.thotada created an issue. See original summary.

rakshith.thotada’s picture

StatusFileSize
new1.42 KB
rakshith.thotada’s picture

Status: Needs work » Needs review
rakshith.thotada’s picture

Title: Integrity constraint violation: 1062 Duplicate entry '4-openid_connect.myProvider » Integrity constraint violation: 1062 Duplicate entry openid_connect.myProvider
rakshith.thotada’s picture

StatusFileSize
new1.37 KB
rakshith.thotada’s picture

Assigned: rakshith.thotada » Unassigned

dressedk made their first commit to this issue’s fork.

dressedk’s picture

I have opened an issue fork for for this issue.

I suggest a few changes to the patch by #rakshith.thotada :

1. Place the try/catch block within the foreach loop, as I don't think we want to skip the whole update hook. By placing it inside the foreach loop, we make sure that the update hook still runs through all entries.

2. Instead of catching a generel exception, I suggest we only want to catch the "IntegrityConstraintViolationException".

d.steindl made their first commit to this issue’s fork.

d.steindl’s picture

Since the `openid_connect_authmap` table can have thousands of entries, I've changed the updater to use Drupals `$sandbox` for the update hook `openid_connect_update_8204`. The updater now processed 500 entries for each operation instead of all at once.

And in order to ensure that each entry is only processed one time (even in the case that the updater fails), I've added the deletion of the processed entry from the old `openid_connect_authmap` directly after the new entry was created in the `authmap` table.

With these adjustments, the update should now complete safely and efficiently, even for large installations.