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

Since 3.0.165 subfield selectors do not work anymore #1400

Closed
szopos opened this issue Jun 28, 2021 · 11 comments
Closed

Since 3.0.165 subfield selectors do not work anymore #1400

szopos opened this issue Jun 28, 2021 · 11 comments

Comments

@szopos
Copy link

szopos commented Jun 28, 2021

After I updated PW to 3.0.165 I got an Internal Server error when using subfield selectors like $selector = "template=produkt, produkt_hersteller.title%=$q";

The selector shoud work like it worked before version 3.0.165.

Now I ab getting an Internal Server error. In dev mode:
Rats… Fehler: Exception: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters (in wire/core/PageFinder.php line 627)

#0 wire/core/Wire.php (400): PageFinder->___find(Object(Selectors), Array)
#1 wire/core/WireHooks.php (823): Wire->_callMethod('___find', Array)
#2 wire/core/Wire.php (465): WireHooks->runHooks(Object(PageFinder), 'find', Array)
#3 wire/core/PagesLoader.php (350): Wire->__call('find', Array)
#4 wire/core/Pages.php (255): PagesLoader->find('template=produk...', Array)
#5 wire/core/Wire.php (397): Pages->___find('template=produk...')
#6 /home/httpd/v

My initial selector was
$selector = "template=produkt, check2|check_temp=1, (title|text|text_editor_minimal|text_editor|text_editor2|text_editor3|search_index~=$q), (produkt_hersteller.title%=$q), (produkt_bereiche.title%=$q), (produkt_anwendungen.title%=$q), (produkt_verwendungen.title%=$q), (produkt_geratetypen.title%=$q), (produkt_gruppen.title%=$q), (produkt_verdichter.title%=$q), (produkt_kaltemittel.title%=$q), (produkt_gwp.title%=$q)";

Now I ended with this one (I avoided subselectors):
$selector = "template=produkt, check2|check_temp=1, (title|text|text_editor_minimal|text_editor|text_editor2|text_editor3|search_index%=$q)";

ProcessWire version: 3.0.165

  • PHP version: 7.3.28
  • Any 3rd party modules that are installed and could be related to the issue: I am using teppos SearchEngine Module but the search occures "manually", meaning with PW $pages->find($selector) engine. I already posted this issue in the SearchEngine support forum. It looks like this ist an PW issue, not an SeerchEngine Module bug.
@adrianbj
Copy link

@szopos - could you try the latest dev version of PW to see if the issue still exists?

@szopos
Copy link
Author

szopos commented Jun 30, 2021

@szopos - could you try the latest dev version of PW to see if the issue still exists?

I upgraded to DEV 3.0.179… same problem. Now the error comes from line 670…

@ryancramerdesign
Copy link
Member

ryancramerdesign commented Jul 9, 2021

@szopos I can't seem to duplicate this one. The test I used was like the first one you indicated, though I'm not sure what is in your $q variable, so maybe that is a factor?

$items = $pages->find("template=blog-post, categories.title%=database"); 
echo $items->implode("<br />", "{title}: {categories.title}");

The result was a list of matched pages and the titles of their categories (all including the word "database").

@szopos
Copy link
Author

szopos commented Jul 13, 2021

@szopos I can't seem to duplicate this one. The test I used was like the first one you indicated, though I'm not sure what is in your $q variable, so maybe that is a factor?

$items = $pages->find("template=blog-post, categories.title%=database"); 
echo $items->implode("<br />", "{title}: {categories.title}");

The result was a list of matched pages and the titles of their categories (all including the word "database").

In fact $q should be a string. The string comes from the search field.

$q = $sanitizer->text($input->get->q);
if($q) {
    $q = $sanitizer->selectorValue($q);
    $selector = "template=produkt, check2|check_temp=1, (title|text|text_editor_minimal|text_editor|text_editor2|text_editor3|search_index%=$q)";
//…and so on…

I tried again to add those parts that are causing the error, like:
(produkt_verwendungen.title%=$q)
I realised that the error occures when one of them has NO result.
Example:

$q="panasonic";
…(produkt_manufacturer.title%=$q)…
// No error because I have "panasonic" products
$q="sony";
…(produkt_manufacturer.title%=$q)…
// Produces error because I have no "sony" products

I also tried to run the search with a hardcoded string:
$q="sony";
Same result.

Any ideas?

@ryancramerdesign
Copy link
Member

ryancramerdesign commented Jul 16, 2021

@szopos I've translated your new selector to this here for testing:

$q = 'lkjaeflkjef'; // text that does not appear
$items = $pages->find("template=blog-post, toggles=prevnext|comments, (categories.title|title|body%=$q)");

I also tried this, since just one selector in parenthesis wouldn't be useful:

$items = $pages->find("template=blog-post, toggles=prevnext|comments, (categories.title%=$q), (title|body%=$q)");

So far I still cannot duplicate the issue. I'm starting to wonder if it might be coming from one of the Fieldtype modules you have in use that is used by one of these fields: text, text_editor_minimal, text_editor, text_editor2, text_editor3, search_index. Can you tell me what Fieldtypes are used by those fields?

Would it be possible for you to edit the /wire/core/PageFinder.php file to enable additional debugging info? If so, on line 664 is this:

//if($this->config->debug) $error .= " - " . $query->getQuery() . ' ' . print_r($query->bindValues, true);

Uncomment that line by removing the two // at the beginning, and then run your test again. The error message should now include the full SQL query. If you could paste in the full resulting error message, that might help point us in the right direction. (also make sure $config->debug = true; in your /site/config.php file)

@szopos
Copy link
Author

szopos commented Jul 21, 2021

@ryancramerdesign

I uncommented the line 664 and this ist the error message when I am searching for an non existing string like "ggg":

"Look out… Fehler: Exception: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters - SELECT pages.id,pages.parent_id,pages.templates_id
FROM pages
LEFT JOIN pages_access ON (pages_access.pages_id=pages.id AND pages_access.templates_id IN(2,3))
LEFT JOIN field_check2 AS field_check2 ON field_check2.pages_id=pages.id AND (((field_check2.data=:pf78s0X ) ))
LEFT JOIN field_check_temp AS field_check_temp ON field_check_temp.pages_id=pages.id AND (((field_check_temp.data=:pf79s0X ) ))
WHERE (pages.templates_id=:i0X)
AND (pages.status<:i1X)
AND (((field_check2.data=:pf78s0X ) )
OR ((field_check_temp.data=:pf79s0X ) ) )
AND pages.templates_id NOT IN(2,3)
AND pages_access.pages_id IS NULL
AND (
pages.id IN (
SELECT pages.id
FROM pages
LEFT JOIN field_title AS field_title ON field_title.pages_id=pages.id AND (((((field_title.data RLIKE :pf81s0X)) ) ))
LEFT JOIN field_text AS field_text ON field_text.pages_id=pages.id AND (((((field_text.data RLIKE :pf82s0X)) ) ))
LEFT JOIN fi "

This is what I get when I am searching an existing string like "panasonic":

"Ouch… Fehler: Exception: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters - SELECT pages.id,pages.parent_id,pages.templates_id
FROM pages
LEFT JOIN pages_access ON (pages_access.pages_id=pages.id AND pages_access.templates_id IN(2,3))
LEFT JOIN field_check2 AS field_check2 ON field_check2.pages_id=pages.id AND (((field_check2.data=:pf78s0X ) ))
LEFT JOIN field_check_temp AS field_check_temp ON field_check_temp.pages_id=pages.id AND (((field_check_temp.data=:pf79s0X ) ))
WHERE (pages.templates_id=:i0X)
AND (pages.status<:i1X)
AND (((field_check2.data=:pf78s0X ) )
OR ((field_check_temp.data=:pf79s0X ) ) )
AND pages.templates_id NOT IN(2,3)
AND pages_access.pages_id IS NULL
AND (
pages.id IN (
SELECT pages.id
FROM pages
LEFT JOIN field_title AS field_title ON field_title.pages_id=pages.id AND ((((
MATCH(field_title.data) AGAINST(:pf81s0X IN BOOLEAN MODE)) ) ))
LEFT JOIN field_text AS field_text ON field_text.pages_id=pages.id AND ((((
MATCH(field_text.dat "

I am using the "original" selector:

$selector = "template=produkt, check2|check_temp=1, (title|text|text_editor_minimal|text_editor|text_editor2|text_editor3|search_index~=$q), (produkt_hersteller.title%=$q), (produkt_bereiche.title%=$q), (produkt_anwendungen.title%=$q), (produkt_verwendungen.title%=$q), (produkt_geratetypen.title%=$q), (produkt_gruppen.title%=$q), (produkt_verdichter.title%=$q), (produkt_kaltemittel.title%=$q), (produkt_gwp.title%=$q)";

And these are the field types:

text:
Text ML

text_editor_minimal:
Textarea ML >
CKEditor
(Format, Styles, -, Bold, Italic, Subscript, Superscript,-, RemoveFormat
PWLink, Unlink
NumberedList, BulletedList
Sourcedialog),
Hanna Code Textformatter

text_editor,
text_editor2,
text_editor3:
Textarea ML >
CKEditor
(Format, Styles, -, Bold, Italic, JustifyBlock, JustifyCenter, JustifyLeft, JustifyRight, -,Subscript, Superscript,-, RemoveFormat
NumberedList, BulletedList, -, Blockquote
PWLink, Unlink, Anchor
Table, HorizontalRule, SpecialChar
PasteText, PasteFromWord
Scayt, -, Sourcedialog),
Hanna Code Textformatter

search_index:
Textarea ML >
Textarea
(This field is populated via hook on page save to store some strings for the search engine.)

The other fields are Select Options fileds.

template=produkt are children of a PageTable field.

@ryancramerdesign
Copy link
Member

@szopos Thanks for the additional info. I will go through this in more detail, but had a quick thought I wondered if you could test with your query. If you remove the Options fields from your selector (which I'm thinking is this check2|check_temp=1), does it still get the error?

@szopos
Copy link
Author

szopos commented Jul 26, 2021

@ryancramerdesign
I removed "check2|check_temp=1" and this ist the error when I am searching for an existing string:

Dangit… Fehler: Exception: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters - SELECT pages.id,pages.parent_id,pages.templates_id
FROM pages
LEFT JOIN pages_access ON (pages_access.pages_id=pages.id AND pages_access.templates_id IN(2,3))
WHERE (pages.templates_id=:i0X)
AND (pages.status<:i1X)
AND pages.templates_id NOT IN(2,3)
AND pages_access.pages_id IS NULL
AND (
pages.id IN (
SELECT pages.id
FROM pages
LEFT JOIN field_title AS field_title ON field_title.pages_id=pages.id AND ((((
MATCH(field_title.data) AGAINST(:pf79s0X IN BOOLEAN MODE)) ) ))
LEFT JOIN field_text AS field_text ON field_text.pages_id=pages.id AND ((((
MATCH(field_text.data) AGAINST(:pf80s0X IN BOOLEAN MODE)) ) ))
LEFT JOIN field_text_editor_minimal AS field_text_editor_minimal ON field_text_editor_minimal.pages_id=pages.id AND ((((
MATCH(field_text_editor_minimal.data) AGAINST(:pf81s0X IN BOOLEAN MODE)) ) ))
LEFT JOIN field_text_editor AS field_text_editor ON field_text_editor.pag

and this ist the error when I am searching for a not existing string:

Oops… Fehler: Exception: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters - SELECT pages.id,pages.parent_id,pages.templates_id
FROM pages
LEFT JOIN pages_access ON (pages_access.pages_id=pages.id AND pages_access.templates_id IN(2,3))
WHERE (pages.templates_id=:i0X)
AND (pages.status<:i1X)
AND pages.templates_id NOT IN(2,3)
AND pages_access.pages_id IS NULL
AND (
pages.id IN (
SELECT pages.id
FROM pages
LEFT JOIN field_title AS field_title ON field_title.pages_id=pages.id AND (((((field_title.data RLIKE :pf79s0X)) ) ))
LEFT JOIN field_text AS field_text ON field_text.pages_id=pages.id AND (((((field_text.data RLIKE :pf80s0X)) ) ))
LEFT JOIN field_text_editor_minimal AS field_text_editor_minimal ON field_text_editor_minimal.pages_id=pages.id AND (((((field_text_editor_minimal.data RLIKE :pf81s0X)) ) ))
LEFT JOIN field_text_editor AS field_text_editor ON field_text_editor.pages_id=pages.id AND (((((field_text_editor.data RLIKE :pf82s0X)) ) ))
LEFT JOIN field

@ryancramerdesign
Copy link
Member

@szopos I still can't duplicate here, so I think we'll need to wait and see if the issue arises for anyone else. So far it seems to be isolated to this report. One thing I notice is that the queries you pasted in are partial queries, like they've been truncated, but I think that's just because it's hitting a max length on the exception message or something. But there are no positional parameters in the partial queries we can see, so the error doesn't match up to anything tangible just yet, but thanks for pasting it in nevertheless.

The other thing that might be worth trying is to keep simplifying your selector until the error disappears; then make note of what you removed for the error to disappear, and try using it in a simpler test case to see if it also appears there. That might help narrow in on something specific that would be easier to reproduce.

Lastly, it might also be worth updating to the latest dev branch, just in case this is something isolated to the version you are using.

@matjazpotocnik
Copy link
Collaborator

@szopos, did you try the latest dev version?

@matjazpotocnik
Copy link
Collaborator

@szopos I'm closing this issue, please comment again to reopen.

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

No branches or pull requests

4 participants