With a persistent entity cache, this means the following problem is very easy to replicate:

1) Create node A1
2) Translate node A1 as A2

The database is correct for both nodes (both tnids pointing to the nid for A1), but the load cache still contains the untranslated version of A1. If you view the translations for A2 you will see both nodes. If you view the translations for A1 you will see only A1.

If A1 is flushed from the cache at this point, things will resolve themselves, as the database is still correct.

If you edit and save A1 again before the cache is flushed, the untranslated state of A1 will be saved to the database.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jweowu’s picture

Version: 7.20 » 7.x-dev
Status: Active » Needs review
FileSize
2.61 KB
jweowu’s picture

Issue summary: View changes

Linked to example of persistent entity load cache

hefox’s picture

Linking to issues in i18n and entitycache.

Confirming the bug, will test the patch.

hefox’s picture

Patch works :)

jweowu’s picture

Are you happy to make this RTBC, or do you want additional eyes on it? (noting that it took more than a year to get your own response).

If you want more review from others, perhaps adding a note to that effect to your Related Issues would be of benefit?

hefox’s picture

Updated related issues with inquiry to review the core patch.

I'm not comfortable be the only review of a core patch (though note this did go through a qa process where it was tested on a sandbox then in a more production like environment).

ricovandevin’s picture

I've reviewed the patch from #1. It looks ok to me and it solves the problem we had with the combination of i18n and entitycache.

Do we make it RTBC or do we wait for another review?

mgifford’s picture

It's been 2 years, so not sure that waiting for another review is a good idea.

Is this also a problem in Drupal 8?

Has anyone installed this in a production environment?

Is a SimplyTest.me environment like this sufficient to reproduce the problem with & without the patch?

jweowu’s picture

FWIW I wrote the patch, and have been using it in a production environment ever since.

For testing in SimplyTest.me, you only need to add entitycache. You don't need the i18n or variable modules.

Steps to reproduce/demonstrate (see also the original description for this issue).

* Enable core Content Translation (and Locale dependency), and contrib Entity Cache modules.
* Add a language: admin/config/regional/language/add
* Edit a content type: admin/structure/types/manage/page and under Publishing settings choose "Enabled, with translation".
* Add a page of that type: node/add/page, selecting a language.
* Go to the translate tab, and add a translation for the other language.
* Visit the translate tab for the new translation. You should see both nodes.
* Visit the original node, and then go to its translate tab.

Without the patch: The translation node is not shown; and if you now edit and save the original node (thus updating the database with the incorrect state) the translation relationship is permanently lost -- neither node knows about the other one.

With the patch: The translation node is shown, and the nodes can safely be edited and saved.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

I confirmed this here:
Without patch - http://s6c81708bf964fd1.s3.simplytest.me
With patch - http://s741d37b94635b55.s3.simplytest.me

I can confirm that the relationship is lost without the patch.

jweowu’s picture

I should really have mentioned how to observe the other fixes as well. It can be beneficial to add & enable the devel module as well, so that you can take a look at the tnid properties of the nodes.

In each case start with a translated node, clear the caches (admin/config/development/performance) and then view all nodes to ensure they are correctly loaded in entitycache.

1. Edit the source node and attempt to "Flag translations as outdated" (under the Translation settings fieldset).

Without the patch, this will have no effect on the translations, until the cache is cleared.

2. Delete the source node, and check the translations tab for one of the remaining nodes in the set.

Without the patch, there will now be no "Source" node in the translation set (as all the nodes will still have a tnid set to the nid of the deleted source node).

(As before, editing and saving one of the inconsistent nodes afterwards will make the incorrect state permanent.)


(The following has now been logged as #2367939: Translation sets should be 'removed' when they contain only one node).

As it happens, I've spotted another core bug while writing this. translation_remove_from_set() runs during hook_node_delete() which is before the node is removed from the database. That means that the "there is only one node left in the set" case will never occur (unless we are deleting the only node left in the set) because the COUNT query result will include the node being deleted. I'm 99% certain that the intention here was that if you reduce the set to a single node, it will revert to a tnid of zero (which is the same state as when you initially create a new un-translated node).

n.b. The code for choosing a new translation node in the other branch is still okay, because in that case the db_update() query has set the tnid of the node being deleted to zero before it queries for other nodes with the original tnid, so that query doesn't include the node being deleted.

I don't know whether to add a fix for that into this patch. I think I'd rather make that a separate issue. Perhaps if this one gets committed, we could then quickly roll a patch for this other issue and get it reviewed as well.

ricovandevin’s picture

I agree on the status of RTBC for this issue. Please commit this patch.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1: drupal-translation_load_cache-1936942-1.patch, failed testing.

Status: Needs work » Needs review
jweowu’s picture

That seemed random. Is the testbot now automatically re-testing RTBC patches after core commits?

I'm assuming a false-positive, but I may have requested the re-test too soon to get a different result.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1: drupal-translation_load_cache-1936942-1.patch, failed testing.

jweowu’s picture

What the heck is going on with the test bot? This is really annoying. It's hard enough to get Drupal 7 bugs looked at, without RTBC patches being arbitrarily marked as failures like this.

Status: Needs work » Needs review
jweowu’s picture

Status: Needs review » Reviewed & tested by the community

Fixing the status.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1: drupal-translation_load_cache-1936942-1.patch, failed testing.

Status: Needs work » Needs review
jweowu’s picture

Status: Needs review » Reviewed & tested by the community

Anyone know offhand if there's an existing d.o issue for this testbot problem?

jweowu’s picture

Much appreciated, dcam.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks! As far as I can see, this doesn't affect Drupal 8.

As it happens, I've spotted another core bug while writing this. translation_remove_from_set() runs during hook_node_delete() which is before the node is removed from the database.
...
I don't know whether to add a fix for that into this patch. I think I'd rather make that a separate issue. Perhaps if this one gets committed, we could then quickly roll a patch for this other issue and get it reviewed as well.

Yeah, a separate issue for that sounds like a good idea.

  • David_Rothstein committed 5aede0d on 7.x
    Issue #1936942 by jweowu: Fixed translation_node_insert() updates the...
jweowu’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.