Problem/Motivation
The problem occurs through the API and the GUI.
Steps to reproduce:
- $nl = entity_load("node", 3)->addTranslation("nl");
- $nl->setNewRevision();
- $nl->save();
Now in hook_node_update $entity->getRevisionId() will be equal to $entity->original->getRevisionId() and both will point to the previous revision id.
This is critical, as you might have other entities referencing the revision id of the entity being updated and updated on revision id update in this hook, but as in this hook we do not propery receive the new revision id this might lead to data loss.
This is caused by the entity keys and translatable entity keys not being passed around be reference between translations, so changing it on one translation does update it on others.
Proposed resolution
Ensure that those arrays are stored by reference.
Remaining tasks
discuss
User interface changes
none
API changes
discuss
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | hook_entity_type_update-2542762-8-interdiff.txt | 586 bytes | sasanikolic |
| #8 | hook_entity_type_update-2542762-8.patch | 2.53 KB | sasanikolic |
| #6 | entity-translation_keys-2542762-6.interdiff.txt | 1.55 KB | plach |
| #6 | entity-translation_keys-2542762-6.patch | 2.55 KB | plach |
Comments
Comment #1
catchThis would block an 8.x port of CPS.
Comment #2
berdirCan you clarify "used to work"? How long a go?
This could have been caused by #2478459: FieldItemInterface methods are only invoked for SQL storage and are inconsistent with hooks, or maybe also the *very* recently committed #2513094: ContentEntityBase::getTranslatedField and ContentEntityBase::__clone break field reference to parent entity.
But looking at the code, I can't really see why this would happen.
There is a strange inconsistency, there are two saveRevision() calls, one
$entity->{$this->revisionKey} = $this->saveRevision($entity);
and the other:
$record->{$this->revisionKey} = $this->saveRevision($entity);
But saveRevision() also sets that key, so that return shouldn't even be necessary?
Comment #3
plachWorking on a failing test for now.
Comment #4
hchonov@berdir:
I am not really sure when exactly it was working properly but for sure with beta 11 it was ok.
Unfortunatelly I am not able to debug at the moment and switch to previous betas to check when exactly the problem was introduced.
But here a test demonstrating the problem.
Comment #6
plachLet's try this...
Comment #7
berdirNitpick: entity test is already enabled in the parent test class.
Updated the issue summary to explain the fix. RTBC after that.
Comment #8
sasanikolic commentedRemoved
entity_testfrom the test and rerolled.Comment #10
hchonov@berdir:
I thought, that in each class extending we are overwriting the modules to be installed and not extending them?
Comment #11
berdirNo, they are always extended.
Comment #13
plachComment #14
xjmComment #15
plachRTBC + 1
Comment #16
plachActually, @Berdir already signed-off this in #7, as #8 addresses his only remark.
Comment #17
alexpottNice test coverage. Committed 3532edb and pushed to 8.0.x. Thanks!