Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years 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:

Description

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 3 years ago.

Download all attachments as: .zip

Change History (12)

#1 @genosseeinhorn
3 years ago

  • Keywords has-patch added

#2 @azouamauriac
3 years 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?

Thanks.

#3 @SergeyBiryukov
3 years ago

  • Milestone changed from Awaiting Review to 6.0

#5 @peterwilsoncc
2 years 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
2 years 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.


2 years ago

#8 @audrasjb
2 years 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
2 years ago

  • Keywords commit added

Thanks JB.

#10 @peterwilsoncc
2 years 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.