Node translation doesn't prevent duplicates

nedjo - January 8, 2009 - 17:28
Project:Drupal
Version:6.x-dev
Component:translation.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:patch (to be ported)
Issue tags:i18n sprint
Description

If a user returns to a page where a translation was previously created, s/he gets the same form and can create a duplicate translation.

Steps to recreate:

* Designate the page content type as translatable
* Enable two languages (en, fr)
* Create a page in en
* Translate to fr, noting the page, e.g., node/add/page?translation=1&language=fr
* After saving, return to the same page. Fill out the form again and submit.

Result:

* Two different translations in French, both with the same tnid.

Attached patch prevents this error by testing for existing translations in the requested language.

AttachmentSize
translation-prevent-duplicate.patch1.45 KB
Testbed results
translation-prevent-duplicate.patchre-testing

#1

nedjo - January 9, 2009 - 17:28

#2

Damien Tournoud - January 9, 2009 - 18:19
Status:needs review» needs work

We also need a check for this at submit time.

#3

nedjo - January 9, 2009 - 18:26

Good point.

I guess this would be a translation_nodeapi_validate() function:

* Test for node type is translatable

* Determine the applicable tnid by checking node->tnid or node->translation_source->tnid

* get translations (translation_node_get_translations($tnid), set form error on 'language' field if the language value is already in the translations array.

#4

Damien Tournoud - January 9, 2009 - 18:28

@nedjo: sounds good.

#5

catch - January 19, 2009 - 20:35
Status:needs work» needs review

I added translation_nodeapi_validate() but then discovered that hook_nodeapi_prepare() actually fires even when using the back button, and since it was wiping out the node->language etc. before we got to submit, we end up with the same drupal_set_message() and no duplicate on submit anyway.

So, this patch keeps the _prepare(), doesn't add a validate, and adds tests for both visiting the node/add page again manually, and also a resubmission of the same form (which is equivalent to using the back button).

In both cases, you can create the node you're posting, but it'll simply not have a tnid - it'll be new content in it's own right. I'm not convinced this is ideal from a usability standpoint (although you're already at this page incorrectly anyway if you get there) - but it does fix the bug.

This could probably do with some manual testing by someone to confirm the same behaviour I'm getting - i.e. that we really don't need a _nodeapi_validate(). I think if we were to remove the early return; in _prepare() then we'd actually need the _validate() as well, which'd allow for form_set_error() to prevent posting at all - but that's adding extra code to do much the same thing, so if it's not needed, I don't think we should go out of our way to add it in.

AttachmentSize
duplicate_translations.patch 3.25 KB
Testbed results
duplicate_translations.patchre-testing

#6

catch - January 19, 2009 - 21:50

Discussed this with nedjo in irc, and there's situtations where you might get the _validate() being called in contrib even if it doesn't happen in core. So I've added that back in.

AttachmentSize
duplicate_translations.patch 4.15 KB
Testbed results
duplicate_translations.patchfailedFailed: Failed to apply patch. Detailed results

#7

stella - January 23, 2009 - 21:34

I tested this and it all works great, including tests.

Cheers,
Stella

#8

stella - February 2, 2009 - 23:05
Status:needs review» reviewed & tested by the community

A quick summary of the issue:

Issue:

  • You can create multiple translations of a node, in the same language, by visiting the 'add translation' url directly, e.g. node/add/page?translation=1&language=fr

Patch:

  • Ensures a translation for that node and language doesn't already exist before displaying the 'add node' form, and before it is saved to the database.
  • An error message is displayed if the translation is already present.
  • Includes a test which ensures duplicate translations can not be created.

Cheers,
Stella

#9

System Message - March 8, 2009 - 09:20
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#10

stella - March 9, 2009 - 02:17
Status:needs work» needs review

Patch re-roll

AttachmentSize
duplicate_translations.patch 4.14 KB
Testbed results
duplicate_translations.patchpassedPassed: 10613 passes, 0 fails, 0 exceptions Detailed results

#11

stella - March 9, 2009 - 03:15
Status:needs review» reviewed & tested by the community

Marking back to RTBC

#12

System Message - March 13, 2009 - 05:15
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#13

stella - March 13, 2009 - 21:04
Status:needs work» needs review

Marking for a retest

#14

stella - March 13, 2009 - 21:23
Status:needs review» reviewed & tested by the community

moving back to RTBC

#15

webchick - March 17, 2009 - 04:22
Version:7.x-dev» 6.x-dev
Status:reviewed & tested by the community» patch (to be ported)

Oops. Sorry! I thought I had committed this already!

Committed to HEAD. :)

Marking down to 6.x, as I believe this is an issue there as well, yes?

 
 

Drupal is a registered trademark of Dries Buytaert.