When displaying forum topics, I noticed I had a coouple of duplicate topics shown. Deleting one of the topic also deletes the other so it points to the same node. I looked in the forum_index table and saw the duplicates entries there.

Since I can't reproduce the problem, can the index on the nid column be changed to unique so we could perhaps catch any programmation error ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

filijonka’s picture

Status: Active » Postponed (maintainer needs more info)

If you don't know how to reproduce a problem then it's kind of hard to debug and find out why.

inform us more when you're able to reproduce the problem.

jthorson’s picture

Unfortunately, we can't set the nid column index to 'unique', as that would break revisions support.

clauded’s picture

Thanks for the info.

I was able to reproduce the problem by making a revision of a forum post. When I'm logged on as an admin, the forum topic list displays duplicates if there's a revision for a topic. Is this a bug or is this by design ?

clauded’s picture

Sorry, I double checked and the duplicate entry in the index happens when I edit an already existing topic and save it.

larowlan’s picture

Do you have any node access modules enabled (which would cause query rewriting)?

clauded’s picture

Yes, I have Forum Access, ACL and Content Access.

larowlan’s picture

Can you disable those and report back?
The base query from forum is rewritten by those modules and perhaps they don't allow for revisions.
If that makes no difference then we'll need to look at forum more closely.

clauded’s picture

I disabled all 3 modules, reconstructed permissions but I still have the problem : duplicate row in forum_index when I edit the main topic (no entry in the revision field, only edit the body and save). I also noticed that updating many times the main topics will only generate one duplicate row.

I enabled unique index on the forum_index table and got this :

PDOException : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '111-10-0-1330358523' for key 1: 
UPDATE {forum_index} SET comment_count=:db_update_placeholder_0, last_comment_timestamp=:db_update_placeholder_1 WHERE (nid = :db_condition_placeholder_0) ; Array ( [:db_update_placeholder_0] => 14 [:db_update_placeholder_1] => 1330358523 [:db_condition_placeholder_0] => 111 ) dans _forum_update_forum_index() 
(ligne 1252 dans /home/mysite/public_html/modules/forum/forum.module).

I don't understand how an update statement can trigger a duplicate row in the table.

filijonka’s picture

Hi

Do you think you could make us a step by step list?

Personally never used forum module butif have alist that I can follow how to reconstruct the error.

jemond’s picture

I am also getting this issue. I believe the bug is in forum_field_storage_pre_update() in forum.module.

Regarding this if statement:

    // We don't maintain data for old revisions, so clear all previous values
    // from the table. Since this hook runs once per field, per object, make
    // sure we only wipe values once.
    if (!isset($first_call[$entity->nid])) {

This just ensures the delete fires once, but the insert query that follows would occur each time this function is called. The comment makes it seem that perhaps the insert should be running once per func call as well?

I tested this on my install and it fixed the issue, which I was able to repro by simply editing a forum node.

jemond’s picture

FWIW, here is what I used in template.php to address this bug until core is patched:

function THEMENAME_preprocess_forum_topic_list(&$vars) {
  $topics = $vars['topics'];
  
  $last_topic = array();
  foreach($topics as $key=>$topic) {
    if(isset($last_topic->nid) && $topic->nid == $last_topic->nid) {
      unset($topics[$key]);
    }

    $last_topic = $topic;
  }

  $vars['topics'] = $topics;
}
clauded’s picture

Well, I've been able to find the module causing it in my case : File (Field) Paths 7.x-1.0-beta3.

I tried your patch (changed "hotness" to my theme name and flushed the cache) and it works with the forum view : no more duplicates.

However, I have a block that displays recent messages and it still shows duplicates (and I still have duplicate entries in the forum_index table).

clauded’s picture

Following #10 advice, I produced a patch to the forum module that seems to correct the problem.

filijonka’s picture

hey

if you instead of using patch in #13,

please try this patch: http://drupal.org/node/681760
there are d6,d7 and d8 releases of it.

larowlan’s picture

clauded at #13 you indicate that the cause of the problem was a contrib module.
Can you either
a) reassign this ticket to that project - or -
b) mark the issue as closed.

Thanks

filijonka’s picture

if you had read #14 you would have seen that this is refering to another contrib and what is most likely the solotion for this problem.

clauded’s picture

I tried the patch in #14 but I can't apply it against the 7.12 version of the node.module. I guess I'll have to wait for the 7.13 release to see if it works.

patch node.module 681760-multi-realm-access-d7-185.patch 
patching file node.module
Hunk #1 succeeded at 3218 (offset -34 lines).
Hunk #2 succeeded at 3246 (offset -34 lines).
Hunk #3 succeeded at 3256 (offset -34 lines).
Hunk #4 succeeded at 3291 (offset -34 lines).
patching file node.module
Hunk #1 succeeded at 3932 with fuzz 1 (offset 1527 lines).
patching file node.module
Hunk #1 FAILED at 15.
Hunk #2 FAILED at 38.
2 out of 2 hunks FAILED -- saving rejects to file node.module.rej
holtzermann17’s picture

I can confirm that the theme-based work-around from #11 works for me.

@clauded: I'm also using File (Field) Paths 7.x-1.0-beta3. Can someone confirm whether this is an issue with core, or an issue with that module?

daften’s picture

I am really wondering why there need to be two entries in the forum_index table for revisioning. They ALWAYS contain the exact same information. revision info should be stored in the revisioning table. With the current way things are handled, a lot of hacks are needed (yes, i call them hacks), to make sure no counts are displayed twice. Just making sure the forum_index table only contains 1 entry per topic would solve these problems.

I'm wondering why this would not possible, what would break exactly?

katannshaw’s picture

I ran into the same problem with the core forum module by doing the following:

1) Creating a new forum topic
2) Editing the topic and kept "Modify current revision, no moderation" selected
3) Saved the post

After doing this, I could see duplicate entries on the forums page and in the forum_index table even though I had selected to have no revision. The only value different in the table was the __pk value. Everything else was exactly the same.

So this is what I tried:

1) I tried the patched referenced on #14 (http://drupal.org/node/681760). Nothing changed, but I could see that it looked like it had already been implemented in my version of Drupal (7.22).
2) I then tried the #13 patch. No success.
3) I eventually fixed the issue editing the theme's template.php file as referenced on #11. I can still see the duplicate entries in forum_index table, but the Forums page at forum/forum-container-name only displays one entry per post.

Thanks.

alb404’s picture

Hi.

Somehow, the line number changed in newer versions of drupal core forum so I've updated #13 patch to match those changes. After I've applied the patch, I had to edit the duplicated nodes before the duplicates were removed in the forum_index table.

This is my first patch, so comments / critics are more than welcome!
This patch applies against Core 7.19 and should work with upper versions.

Hope this help.

alb404’s picture

Ignore this one ...

alb404’s picture

Changed git diff path to be relative to root rather than inside the forum directory.

ayalon’s picture

Please forget all the patchs above. The reason is an old file field paths module.

Just update to the latest dev.
https://drupal.org/project/filefield_paths

You have to delete all duplicates manually.

The fix is here:
https://drupal.org/node/1464404
Referenced here:
https://drupal.org/node/1481260

larowlan’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)
katannshaw’s picture

I updated to the dev version and deleted all of the other old duplicate entries, but duplicate entries are still getting created on my site when a forum item is updated. I also tried patch #23 but it also didn't stop duplicate entries from getting entered into the forum_index table even though revisions are set to off.

Do you have any suggestions on what other steps I should follow?

grigorym’s picture

I have the same problem, even though i have no filefield_paths module at all. I was able to track down it to wysiwyg_fields module, since when i disable it, the problem goes away.

brunodbo’s picture

Version: 7.12 » 7.41
Issue summary: View changes
Status: Closed (works as designed) » Active

Still experiencing this issue in 7.41, without using Filefield Paths, nor any node access modules. Aside from having duplicate rows in the forum_index table, some of those rows also have the duplicate amount of comments counted in the comment_count column (e.g., for a post that has 2 comments, it the comment_count column will have a value of 4).

marksmith’s picture

This problem persists with Drupal 7.57.

Version: 7.41 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Delphine Lepers’s picture

I am submitting a new version of the patch that adds a primary key

Delphine Lepers’s picture

This new version will check for users who already fixed this manually

dhim712’s picture