Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If we use [user:field_first_name] [user:field_last_name]
for patter and users has the same first name and last name. We get error SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
Comments
Comment #2
gaydamaka CreditAttribution: gaydamaka as a volunteer and at FFW commentedComment #3
gaydamaka CreditAttribution: gaydamaka as a volunteer and at FFW commentedComment #4
hass CreditAttribution: hass commentedComment #5
spheresh CreditAttribution: spheresh commentedIt works for me! Thanks @gaydamaka.
I also agree that direct request to the database is very light
but I think to use a user_load_by_name function is better by two reasons:
- This function gets an Entity Storage service which is Entity Storage Interface implementation.
- This solves possible problems in case User Storage will be overridden by one of the modules.
but another side this function load a fully-loaded user object that is not really needed for us in this case.
Comment #6
hass CreditAttribution: hass commentedWe always always always need to use the drupal API.
Comment #7
Ronald van Belzen CreditAttribution: Ronald van Belzen as a volunteer commentedI am unable to reproduce this error.
However, looking at patch #2, I started wondering whether the following instruction should be used in the function realname_update() at all?
Comment #8
hass CreditAttribution: hass commentedWhatever I'm trying here I cannot reproduce the
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
. It's nearly impossible to know what user is the right one, but it all works without errors. Can you document the repro, please?Comment #9
hass CreditAttribution: hass commentedThere may be a simple solution here. Something already done in D7.
We may change label to show the username or ID in brackets. In D7 it was the username.
With ID:
and with username (I think this is better usability than just a number):
This would be just a usability enhancement, not a solution for the SQL issue reported.
Comment #10
hass CreditAttribution: hass commentedgetAccountName()
returns empty value onAnonymous
. Need to investigate.Comment #11
hass CreditAttribution: hass commentedAbove changes are in RC1 and opened a follow up #2881524: getAccountName() returns no username for Anonymous user.
As I'm not able to repro the duplicate entry situation, I'm closing as cannot repro. If you know - how to repro, please reopen with step by step instructions.