-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
translations:find -> Integrity constraint violation: 1062 Duplicate entry #138
Comments
in my case however all keys are always all lowercase.. so not sure if related to that.. hrmm.. will try to drill down further |
ok so I've been debugging the issue and think I found out what's going on.. at least this should help you come up with a fix so I'm tracing the process by adding a bunch of debugging inside the firstOrNewTranslation method I run translations:find and it finds a key called "JSON.category" (which already exists and has already been translated) it runs through firstOrNewTranslation and it looks for an existing database entry with these attributes:
it correctly finds one.. and moves on then it repeats this, this time it looks for these attributes:
Here it will fail to find the existing entry since the "saved_value" in the database happens to be "Category" with a capital.. however this is the translated string so it could have been anything.. it could have been "A Category" for example. It fails to find the existing entry, it then tries to create a new entry and runs into the integrity issue above I feel that the firstOrNewTranslation should probably not be checking for the "saved_value" attribute ever.. right ? I think that's the problem here.. the firstOrNewTranslation method should only ever be checking for the locale, group and key to determine if a key already exists.. not also the value, saved_value and status I added these unsets here
and it makes the problem go away for me |
on a separate but not entirely unrelated note, I'm still confused why this 'json' locale even exists and why the database rows for the 'json' locale contain the same 'value' and 'saved_value' as the 'en' locale rows |
@vesper8, you found a bug. Only locale, group and key should be used for the check. The fix is only using these columns. Reseting other values will cause issues for the following code which uses the attributes to set a new translation if one is not found. if ($checkDB) {
$query = $this->translation->on($this->getConnectionName());
foreach ($attributes as $attribute => $value) {
if ($attribute === 'locale' || $attribute === 'group' || $attribute === 'key') {
$query = $query->where($attribute, $value);
}
}
$translation = $query->first();
}
|
@vesper8, the |
thanks for the quick fix! I just ran a composer update and it didn't get the new version even though you pushed it 2 hours ago
Maybe just a cache issue.. I know github is having problems today |
@vesper8, updated packagist.org manually. There seems to be some glitches on that site and I don't know if it is github's fault or packagist but managed to get myself locked out of my account trying to update github hooks. Bugs are a part of developer's life. ;) |
running translations:find works great the first time I run it, but if I add new keys in my code and run it again I get this error
if I truncate the table and start fresh then it works fine again.. this seems related to the unique indexing on the table but.. how come it fails to see there are already items with the key "category" in the case below and tries to insert them anyway?
The text was updated successfully, but these errors were encountered: