Right ok I have found why it is producing the 404 error but not where the code lives in your theme that is causing it.
404 versions is running this code:
SELECT wp_posts.*
FROM wp_posts
WHERE 1=1
AND wp_posts.post_name = ‘test’
AND wp_posts.post_type = ‘product’
ORDER BY wp_posts.post_date DESC
Which of course does not exist
where as the working version is running this code:
SELECT t.*, tt.*
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
WHERE tt.taxonomy IN (‘brand’)
AND t.slug = ‘test’
LIMIT 1
Which one to run use is being decided by this piece of code:
WP_Query->get_posts()
wp-includes/class-wp-query.php:2831