Download & Extend

Changing the language of a simplenews node throws a PDO error

Project:Simplenews
Version:7.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

To reproduce:

On a clean install, enable i18n and simplenews.

Activate at least two languages, and make the Simplenews newsletter content type translatable.

Create a newsletter node in any language.

Edit the same node, and change the language.

The following error is thrown:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tid' cannot be null: UPDATE {simplenews_newsletter} SET tid=:db_update_placeholder_0, status=:db_update_placeholder_1 WHERE ( (nid = :db_condition_placeholder_0) ); Array ( [:db_update_placeholder_0] => [:db_update_placeholder_1] => 0 [:db_condition_placeholder_0] => 24 ) in simplenews_newsletter_save() (line 1955 of /var/www/sites/drupal/sites/all/modules/contrib/simplenews/simplenews.module).

This is due to the language handling of the nodes in Drupal core.

In simplenews_get_term_values() (copied below for reference), when the language has been changed, the $node->{$category_field['field_name']} property returns a two element array (or possibly more depending on how many active languages there are) which contains a valid entry for the current language, and an empty value for the old language.

So, current($taxonomy) may return an empty value.


function simplenews_get_term_values($node) {
$category_field = simplenews_get_category_field($node->type);
$taxonomy = $node->{$category_field['field_name']};
$term = current($taxonomy);
if (!empty($term)) {
return $term;
}
return FALSE;
}

I'm including a patch which prefers the term associated to the current language of the node.

Comments

#1

AttachmentSizeStatusTest resultOperations
fix_get_term_values-1410330-2.patch625 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 1,436 pass(es).View details

#2

Status:active» needs review

Always set issues to "needs review" if there is patch.

Thanks for debugging and finding this!

What would be lovely is a test for this. We already have tests for content translation, so all that's necessary should be to re-save an existing node with a different language. Can you try that?

#3

Thanks for catching the "needs review" oversight!

I did test the patch before submitting it. After applying the patch, I performed the following:

Resave the node with no changes
Resave the node changing the language
Resave the node changing the language and another value

The error does not appear after applying the patch with these tests.

#4

Yeah, what I meant are *automated tests* with Simpletest :)

Unless you are fine if I call you every time I make a commit and you repeat your checks ;)

#5

That might take more time :)

I actually have never used Simpletest, so this is a great opportunity for me to learn something about it -- however, I won't be able to get to it immediately.

#6

Sure, take your time.

You can also contact me in #drupal-contribute, if I'm around.

As I said, first look at the existing content translation tests, it should require just a few additional lines (like two ;)) to trigger your bug.

#7

Just wanted to ask if you still plan to try and write some tests here.. :)

#8

Here are some tests.

Confirmed that your fix works fine.

AttachmentSizeStatusTest resultOperations
added_tests.patch1.39 KBIdlePASSED: [[SimpleTest]]: [MySQL] 1,487 pass(es).View details

#9

Status:needs review» needs work

The last submitted patch, added_tests.patch, failed testing.

#10

Status:needs work» needs review

#8: added_tests.patch queued for re-testing.

#11

Status:needs review» fixed

Commited and pushed, thanks for helping to fix this.

#12

Thanks Berdir -- I've been out of town and just got back.

#13

Status:fixed» closed (fixed)

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

nobody click here