Wrong number of posts is displayed
| Project: | Drupal |
| Version: | 5.x-dev |
| Component: | forum.module |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | duplicate |
Hello,
I'm a newbie, sorry if I'm doing something wrong.
When forum access module is enabled some users see wrong number of post in "Posts" column on a main forum page (http://www.example.com/forum/)
For example, I have forum container “General questions”, it has few forums, one of them is “Theory”.
Anonymous users can see that this forum has 2 topics and 9 posts on main forum page.
Different authenticated users can see different number of posts (I think it depends on roles that they have).
I have roles “editor”, “moderator” and “administrator”. Users who have these roles can “View this forum”, “Post in this forum”, “Edit posts” and “Delete posts”.
Users who have “editor” role can see that this forum has 2 topics and 16 posts.
Users who have “moderator” role can see that this forum has 2 topics and 37 posts.
Users who have “administrator” role can see that this forum has 2 topics and 9 posts.
9 posts is a correct number.
When I turned off Forum Access module (just removed corresponding flag in Administer\Site building\Modules) the correct number of posts was displayed to all users regardless of their roles. When I turned it on, wrong numbers of posts listed above were displayed again.
Is it a bug? What can be done to fix it?
Drupal 5.7
ACL 5.x-1.6
Forum Access 5.x-1.10
I’ve other modules installed. If it is required I can list them too.
Thank you!

#1
#2
You're saying that 'editor', 'moderator', and 'administrator' all have the same access rights, but they see different numbers of comments?
Please go into the forum as a user in each of the roles and verify that you really see only 9 posts.
#3
Thanks for your answer.
I’ve captured some screenshots and marked some areas on them in order to avoid misunderstanding. Forum is in Russian actually.
'Editor', 'moderator', and 'administrator' have the same access rights in Forum Access module (see forum_access_access_control.jpg). But their roles have different access permissions in Administer > User management > Access control page.
Anonymous user can see that there are 9 posts in highlighted forum. (see anonymous_user_view.jpg). I’ve counted posts manually in this forum – 9 is correct value.
Administrator user can see that this forum has 9 posts.
Authenticated user (testuser2) can see that there are 16 posts. (see authenticated_user_view.jpg)
When authenticated (testuser2) user opens this forum, he can see that it has 2 topics and 7 replies (9 posts totally) (see authenticated_user_view2.jpg)
Moderator (username is moderator1) can see that there are 37 posts. (see moderator_user_view.jpg)
When moderator (user - moderator1) user opens this forum, he can see that it has 2 topics and 7 replies (9 posts totally – that is correct value) (see moderator_user_view2.jpg)
I’ve noticed that number of posts that is shown for a user on a main forum page changes when I assign new (or remove old) roles to that user.
For example, user moderator1 has 3 roles (see moderator1_roles1.jpg). As I wrote above, he can see that forum has 37 posts.
I added one more role to that user (see moderator1_roles2.jpg). Now he can see that forum has 44 posts (see moderator_user_view3.jpg)
I encountered this problem in two different Drupal installations, but most of the additional modules were the same.
#4
Thanks for following up!
That's a very useful observation. What database are you using? PHP version?
#5
I have a few independent Drupal localhost installations and a web installation, all they have wrong number of posts.
My hosting provider has:
PHP Version 5.2.5
MySQL 5
Localhost:
PHP Version 5.2.4
MySQL 5.0.45-community-nt
#6
Good, thanks, I will investigate.
#7
This is a core bug in forum_get_forums(). db_rewrite_sql() turns this
SELECT r.tid, COUNT(n.nid) AS topic_count, SUM(l.comment_count) AS comment_countFROM {node} n
INNER JOIN {node_comment_statistics} l ON n.nid = l.nid
INNER JOIN {term_node} r ON n.nid = r.nid
WHERE n.status = 1
AND n.type = 'forum'
GROUP BY r.tid";
into something like this:
SELECT r.tid, COUNT( DISTINCT(n.nid)) AS topic_count, SUM(l.comment_count) AS comment_countFROM node n
INNER JOIN node_comment_statistics l ON n.nid = l.nid
INNER JOIN term_node r ON n.nid = r.nid
INNER JOIN node_access na ON na.nid = n.nid
WHERE (na.grant_view >= 1
AND ((na.gid = 0 AND na.realm = 'all')
OR (na.gid = 5 AND na.realm = 'acl')
OR (na.gid = 9 AND na.realm = 'acl')
OR (na.gid = 17 AND na.realm = 'acl')
OR (na.gid = 2 AND na.realm = 'content_access_author')
OR (na.gid = 2 AND na.realm = 'content_access_rid')
OR (na.gid = 3 AND na.realm = 'content_access_rid')
OR (na.gid = 4 AND na.realm = 'content_access_rid')
OR (na.gid = 2 AND na.realm = 'forum_access')
OR (na.gid = 3 AND na.realm = 'forum_access')
OR (na.gid = 4 AND na.realm = 'forum_access')))
AND ( n.status = 1 AND n.type = 'forum' )
GROUP BY r.tid
If the na part of the query has multiple matches and we get multiple instances of n.nid, then DISTINCT will remove them for COUNT, but SUM will add them all up and you get the behavior that Bender2008 is reporting.
#8
It's a bug in D6, too. Non-admin users with forum access see the double number of comments.
#9
Node access is badly broken in D6 anyway, but the worst (#153998: Access checks returning NULL is ugly.) should be fixed in D6.3.
Maybe we can fix this as well?
#10
Regarding #7 above with the query example, are we to understand that
this bug is likely to occur when you have more than one node access
module (forum_access, acl, content_access above) AND node_access
gid is as a result repeated?
e.g. you have
OR (na.gid = 2 AND na.realm = 'content_access_author')
OR (na.gid = 2 AND na.realm = 'content_access_rid')
OR (na.gid = 2 AND na.realm = 'forum_access')
this case which I would assume would be responsible for the
extra values passed to the SUM function?
#11
@jaydub: No. You list three (pairs of) parentheses, and each one can yield either TRUE or FALSE. It doesn't matter that the gids all happen to be ==2 in your example. Grants in different realms are completely unrelated, and each realm typically starts numbering its gids from 1.
If more than one parenthesis pair yields TRUE for the same na.nid, then you'll get multiple rows for that one na.nid. The DISTINCT(n.nid) eliminates the duplicates for COUNT(), but SUM() adds up all l.comment_count's without discarding duplicates.
For example if nid=123 matches three parenthesis pairs and it has 5 comments, then it'll contribute 15 to the Posts count.
#12
#153998: Access checks returning NULL is ugly. is fixed for D6 and we can finally start looking at node access again. This issue remains open though...
#13
I think this is a duplicate of #113611: Forum count incorrect when using access control modules. But this contains information that doesn't, so I'll leave them both open (but pointing to each other).
#14
Has anyone looked at this in a while? I would really like to use Forum Access but this bug is a deal breaker b/c it discredits the forum accuracy.
Bump.
#15
#113611: Forum count incorrect when using access control modules
Michelle