I found that simply translating the body field of the Article content type on a new install throws a fatal error :(
- Install a new site with the standard profile.
- Log in as UID 1.
- Enable Content Translation + Language modules.
- Add a second language: go to admin/config/regional/language/add and add a second language (eg. German).
- Enable content translation for the Article content type: go to admin/structure/types/manage/article and enable the following options under "Language settings":
- Show language selector on create and edit pages
- Enable translation
- Enable content translation for the body field: go to admin/structure/types/manage/article/fields/node.article.body/field and enable the option "Users may translate this field".
- Create a node in English: go to node/add/article and create a node, filling in the title and body field. Click on "Save and Publish".
- Create a German translation: go to de/node/1/translations/add/en/de and click on "Save and keep published".
Result:
Integrity constraint violation: 1062 Duplicate entry '1-en' for key 'PRIMARY': INSERT INTO {node_field_revision} (nid, vid, langcode, default_langcode, title, uid, status, created, changed, promote, sticky) VALUES (...) in Drupal\Core\Entity\FieldableDatabaseStorageController->save() (line 693 of /home/pieter/drupal/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php).
Comment | File | Size | Author |
---|---|---|---|
#16 | et-clone_refs_broken-2129039-16.patch | 9.33 KB | plach |
#20 | et-clone_refs_broken-2129039-16-should-fail-tests-only.patch | 7.03 KB | Gábor Hojtsy |
Comments
Comment #1
pfrenssenI rolled the steps above in a test to see if this can be replicated on the test bot.
I find it very strange that I have to add an assertion to detect that an integrity constraint violation occurs during the test. This probably means that the exception is caught before Simpletest can grab it. Makes me wonder how many fatal errors occur during testing now but are simply not detected.
Comment #3
Gábor HojtsyI also reproduced this earlier several times, and we have seen people reproducing it in Prague at the sprint. (There may be other duplicate copies of this) While the translation is actually saved, there is no way out of this error, you need to navigate manually away. Therefore uping to critical.
Comment #4
plachI found out what is causing this: it seems we have some weird issue with field item references, basically we are getting different revision ids per language in the entity object, aw :(
Still looking for the root cause.
Comment #5
Gábor HojtsyAdding more tags.
Comment #6
pfrenssenI also noticed in #2087299: Impossible to save nodes if translation is newer than default language that this happens for other properties on entities, like the 'changed' property on nodes: when you retrieve this you always get it back for a particular translation.
I am also working on this.
Comment #7
plachI think the two issues might be related.
Comment #8
plachThe attched patch should fix the issue.
Since the test posted above more or less replicates what we have now, but just for nodes, and given that the bug lives in
ContentEntityBase
, I'd like to try to provide test coverage for this inEntityTranslationTest
. Couldn't reproduce the issue so far, though.Just a note: this does not happen if you create from scratch a plain content type with just the body field. I usually run the minimal install so I didn't experience this issue previously.
Comment #9
nyirocsaba CreditAttribution: nyirocsaba commentedI'm not yet familiar with the Drupal 8 core, but after doing some late night and morning research on this issue I ended up with the following:
When the new revision get created in the FieldableDatabaseStorageController->saveRevision the new vid is passed only for the active language, which in this particular flow is the german (de).
Comment #10
nyirocsaba CreditAttribution: nyirocsaba commentedComment #11
nyirocsaba CreditAttribution: nyirocsaba commentedUpdate:
1. keep the active language revision id up to date (accidentaly removed in the earlies patch)
2. include pfrenssen's test
Comment #12
plach@nyirocsaba:
Sorry, but I think the approach you are following is not correct: untranslatable fields are not supposed to have different values per language, AAMOF currently we are creating references so that the field item objects for the various languages are always the same, see
ContentEntityBase::getTranslatedField()
.The fact that right now we can somehow store different revisions ids per language in the same entity object is completely wrong and will cause huge problems.
What we need to fix is the root cause, which seems to lie in the entity cloning process, although I am not able to reproduce the bug in the entity translation tests. However, the proper fix should be something along the lines of #8.
Comment #13
hass CreditAttribution: hass commented@Plach: are you not able to repro this issue? I have installed latest dev from scratch with default install (not the minimal) and than you run directly into these issues, once translation get's enabled for article.
Comment #14
plachI am not able to reproduce the issue in a test case dealing only with the entity object.
Comment #15
yched CreditAttribution: yched commented(review of @plach's #8)
While we're in here, the variable names seem really misleading here. What is called $properties is an array of (langcode => FieldItemList for the langcode). So this should be:
Looks like this is done in both cases, so it could go out of the if / else block ?
In the case of untranslatable fields, we only act on $langcode == LANGCODE_DEFAULT because that's the only langcode that's supposed to be present in $this->fields[$name], right ?
So maybe in the case of untranslatable fields, no need to foreach on langcodes, just do the one needed stuff on LANGCODE_DEFAULT ? Would make the logic easier to follow IMO.
Comment #16
plachI was not able to reproduce the issue in the Entity Translation tests but I added test coverage anyway. This merges also the test provided by @pfrenssen with the existing node translation tests. We need quite some refactoring to make those pass with the standard profile (including fixing a bug caused by form cache in the entity form controller).
This should also address @yched's review: I opted for using
$values
instead of$items_by_langcode
(which is quite verbose) for consistency with the field caching code.Comment #17
plachRe-uploading the test-only patch (should fail tests).
Comment #18
plachCome on, bot :(
Comment #19
plachLast try for tonight
Comment #20
Gábor HojtsyDon't know why those did not go for tests... maybe some undocumented file name pattern?!
Comment #22
plachFinally :)
Comment #23
Gábor Hojtsy@yched, @hass, @nyirocsaba, @pfrenssen any feedback on the patch?
Comment #24
yched CreditAttribution: yched commented20: et-clone_refs_broken-2129039-16-should-fail-tests-only.patch queued for re-testing.
Comment #25
yched CreditAttribution: yched commentedOh, sorry - the fails for #20 were expected, actual patch is in #16.
Reviewing.
Comment #26
yched CreditAttribution: yched commentedYup, looks good :-)
(although, not sure why this is filed for content_translation.module while the fix is in ContentEntityBase ?)
Comment #28
yched CreditAttribution: yched commentedRTBC as per #26 - #16 is the patch to commit.
Comment #29
plach16: et-clone_refs_broken-2129039-16.patch queued for re-testing.
Comment #30
Gábor HojtsyLet's get this in the Monday alpha :)
Comment #31
hass CreditAttribution: hass commentedStill get this when adding a translation:
At URL: node/2/translations/add/de/en
InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 691 of core\lib\Drupal\Core\Entity\ContentEntityBase.php).
I have created an English translation of a German article. I also get Article English article 2 has been updated.
EDIT: And afterwards I see two English articles listed on project home (English UI) where only one should be shown. Also with the same URL alias... it's just shown twice. I guess every translation will add an item. If I switch to German I see two times the German article.
Comment #32
plachI saw that in Prague but I was not able to reproduce it reliably. Can you post the steps? I suspect it might be a different issue.
See #2006606: Views rendering ignores entity language, eg: Identical nodes rendered in views when nodes have translations.
Comment #33
hass CreditAttribution: hass commentedIt's easy to repro here. Just add a translation to an existing node and save.
Comment #34
hass CreditAttribution: hass commentedUHHH, uncheck Create new revision!
Comment #35
jthorson CreditAttribution: jthorson commentedJust playing around to look into the untested files issue. Please ignore.
Comment #36
jthorson CreditAttribution: jthorson commentedComment #37
jthorson CreditAttribution: jthorson commentedComment #38
jthorson CreditAttribution: jthorson commentedComment #39
jthorson CreditAttribution: jthorson commentedComment #40
hass CreditAttribution: hass commentedCreated follow up #2137815: InvalidArgumentException: Invalid translation language specified.
Comment #41
jthorson CreditAttribution: jthorson commentedTrying to reproduce #2136501: Sometimes patches are not sent for testbot. ... sorry for the noise. :( Still RTBC, and the patch in #16 is still the one to commit.
Comment #42
jthorson CreditAttribution: jthorson commentedComment #44
jthorson CreditAttribution: jthorson commentedBizarre ... can't explain why the bot wasn't picking up the patches, but can't reproduce it either. :(
Back to RTBC and restored the patch from #16 to the top of the table.
Comment #45
webchickCommitted and pushed to 8.x. Thanks!
Comment #46
tstoecklerSo it seems #41 was committed and not #16: http://drupalcode.org/project/drupal.git/commitdiff/b0ed757
?!
Comment #47
webchickShoot, I am so sorry! This is why I should not commit patches while on the phone. :P~
Reverted previous; committed and pushed #16 to 8.x. Let's see how it likes that. :)
Comment #48
Gábor HojtsyThanks all!