Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ambiguous column in search with ORDER BY #15899

Merged

Conversation

pfigel
Copy link
Contributor

@pfigel pfigel commented Nov 20, 2019

Overview

This fixes an issue where columns whose names are not unique in a search query cause a DB error when they're used as a sort column. The issue can be observed in the contribution search when sorting by contribution status.

Before

Contribution search fails with a DB error when sorting results by contribution status.

After

Contribution search can be sorted by contribution status.

Technical Details

The issue is resolved by using the where field of the field spec, which holds the fully-qualified name of the column.

Comments

I initially thought about fixing this by adding a special case for contribution_status_id somewhere, but then figured this would fix the general case. The downside is that it changes something quite central in CRM_Contact_BAO_Query, so I'm having a hard time deciding on the trade-off.

@civibot
Copy link

civibot bot commented Nov 20, 2019

(Standard links)

@civibot civibot bot added the master label Nov 20, 2019
@pfigel pfigel force-pushed the fix-ambiguous-order-column branch from 6b3ef55 to 4686482 Compare November 20, 2019 23:47
@pfigel
Copy link
Contributor Author

pfigel commented Nov 21, 2019

Surprisingly this doesn't seem to break anything, so marking as ready for review. I did an r-run against all core searches and some custom searches and found no breakage.

Note: There's a non-related, pre-existing issue in the activity search when sorting by activity status.

@pfigel pfigel marked this pull request as ready for review November 21, 2019 01:30
@seamuslee001
Copy link
Contributor

@pfigel do you have any idea when this broke?

@seamuslee001
Copy link
Contributor

(CiviCRM Review Template WORD-1.2)

@eileenmcnaughton @pfigel i think this should probably go into 5.20 thoughts?

@eileenmcnaughton
Copy link
Contributor

5.20 makes sense to me

This fixes an issue where columns whose names are not unique in a
search query cause a DB error when they're used as a sort column.
The issue can be observed in the contribution search when sorting
by contribution status.

The issue is resolved by using the where field of the column spec,
which holds the fully-qualified name of the column.
@pfigel pfigel force-pushed the fix-ambiguous-order-column branch from 4686482 to 452a21f Compare November 21, 2019 09:57
@pfigel pfigel changed the base branch from master to 5.20 November 21, 2019 09:58
@civibot civibot bot added 5.20 and removed master labels Nov 21, 2019
@pfigel
Copy link
Contributor Author

pfigel commented Nov 21, 2019

@seamuslee001 @eileenmcnaughton breakage happened somewhere > 5.13 and <= 5.18. I rebased against 5.20.

@eileenmcnaughton
Copy link
Contributor

Cool - MOP based on @seamuslee001 review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants