Make WordPress Core

Opened 22 months ago

Closed 19 months ago

Last modified 19 months ago

#55218 closed defect (bug) (fixed)

WP_Comment_Query: "Column 'comment_ID' in where clause is ambiguous" when mixing 'include_unapproved' and 'meta_query'

Reported by: genosseeinhorn's profile genosseeinhorn Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.0 Priority: normal
Severity: minor Version: 5.9
Component: Comments Keywords: has-patch has-unit-tests commit
Focuses: Cc:


On my site, I have a custom filter for comments_template_query_args which sets $comment_args['meta_query']. This works fine except when submitting a comment that needs to be approved. The result page will use the ?unapproved= query parameter, triggering the bug.

I've created a patch which I will attach here.

Attachments (1)

ticket55218.patch (1.4 KB) - added by genosseeinhorn 22 months ago.

Download all attachments as: .zip

Change History (12)

#1 @genosseeinhorn
22 months ago

  • Keywords has-patch added

#2 @azouamauriac
22 months ago

Hi there, welcome to wordpress trac, thanks for the report and patch.

Could you please provide a code(snippet) or steps to reproduce the issue?


#3 @SergeyBiryukov
22 months ago

  • Milestone changed from Awaiting Review to 6.0

#5 @peterwilsoncc
20 months ago

Thanks for the report and patch @genosseeinhorn, I can see why that is happening.

I've created linked a pull request that simply contains your patch so I can get the test suite running. I suspect some tests may need to be updated to account for the change in SQL query.

#6 @peterwilsoncc
20 months ago

  • Keywords has-unit-tests added

There were no failing tests.

I've created some that fail without the patch and now pass. They're in the linked pull request too.

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.

20 months ago

#8 @audrasjb
20 months ago

The logic in the PR and unit tests looks good to me.
I added a commit to your PR to address a few docblock changes in your initial proposal :)

#9 @peterwilsoncc
19 months ago

  • Keywords commit added

Thanks JB.

#10 @peterwilsoncc
19 months ago

  • Owner set to peterwilsoncc
  • Resolution set to fixed
  • Status changed from new to closed

In 53291:

Comments: Avoid DB error in comment meta queries.

In WP_Comment_Query always include the table name when referencing wp_comments.comment_ID. This avoids ambiguity in when making meta queries as wp_commentmeta includes a column of the same name.

Follow up to [47887].

Props genosseeinhorn, azouamauriac, audrasjb, peterwilsoncc.
Fixes #55218.

Note: See TracTickets for help on using tickets.