ElasticPress icon indicating copy to clipboard operation
ElasticPress copied to clipboard

BUG: EP crashes trying to use queried object that doesn't exist

Open tomjn opened this issue 2 years ago • 2 comments

Describe the bug

This code in includes/classes/Indexable/Post/QueryIntegration.php assumes that $query->get_queried_object() always returns a term, this is not a safe assumption:

		if ( empty( $query_vars['post_type'] ) ) {
			if ( $query->is_tax() ) {
				$query_vars['post_type'] = get_taxonomy( $query->get_queried_object()->taxonomy )->object_type;
			} elseif ( empty( $query_vars['s'] ) ) {

Steps to Reproduce

Not 100% on the steps that lead to this, only that this is what I got at the other end

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress and ElasticPress information

latest version of elasticpress 4.4.1

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

tomjn avatar Feb 21 '23 13:02 tomjn

Thanks for opening the issue @tomjn but I'm curious to know how this could be a problem. Looking at the is_tax() method, it would return false if queried_object doesn't have a taxonomy set.

felipeelia avatar Feb 21 '23 16:02 felipeelia

I'm not sure how this came about myself, I'm as surprised as you are, and yet it's there. My suspicion is that there are filters interfering here. It's on WP 5.9, no modifications have been made to WP or ElasticPress stock versions. I'm not 100% sure how to reliably reproduce it either.

At a minimum I'd separate out the chained calls to make debugging easier.

tomjn avatar Feb 21 '23 21:02 tomjn