Sinmok

Issue with has_parent selector

Recommended Posts

Hello,

I'm having trouble with a has_parent selector..which seems to work..only sometimes.

I've got a page tree like so (ids are made up for demo purposes)

Home
    Page 1 (id = 1050)
        sub 1
        sub 2
   Page 2 (id = 1080)
        sub 3
        sub 4
   Page 3  (id = 1090)
        sub 5
            sub 6
                 sub 7
            sub 8
                  sub 9

The really weird thing is that the same selector with different page id returns something unexpected..despite the only change being the page id

 

for example, i'm getting

$result = $pages->find("has_parent=1050") //returns a page array of 2 pages

$result = $pages->find("has_parent=1080") // returns an empty page array (WHY?!)

$result = $pages->find("has_parent=1090") //returns a page array of 5 pages

is there anything that could be causing the selector for page id 1080 to return nothing? the templates, access control and all that are all exactly the same

Are there any other known variables that might affect the result of a 

has_page

 selector?

I'm using ProcessWire 2.3.0

Edit: Basically, all I need is a PageArray of all descendants of a given page - do you know of another way of doing this?

Share this post


Link to post
Share on other sites

Have you double checked that the ids of your pages are correct?

$ids = array(1050, 1080, 1090);

foreach($ids as $id) {
    $parent = $pages->get($id);
    if (0 < $parent->id) {
        // page is found, lets call the selector
        $result = $pages->find("has_parent=" . $parent);
        echo "<p>found {$result->count} pages</p>";
    } else {
        echo "<p>wrong ID for parent!</p>";
    }
}

Share this post


Link to post
Share on other sites

I am absolutely sure they are the correct page ids.

$p = $pages->get(1080) // returns the page i want

$result = $pages->find("has_parent=$p") // still empty

and produced the same result..

Share this post


Link to post
Share on other sites

ok, then add a "include=all" to the selector, just to be sure that there are no pages get excluded because of restrictions!

$result = $pages->find("has_parent=$p, include=all");

Share this post


Link to post
Share on other sites

Also worth noting that the following does not work either:

$p = $pages->get(1080) // returns the page I wanted

$r = $p->find("") //returns empty..

//as does

$r = $p->find("id>0") //also returns empty

however

$p->children //DOES return a page array

This DOES work on other pages that has children. Whaaa

Share this post


Link to post
Share on other sites

You have moved those pages around from amother parent? Move those out of the parent and then back in. Works?

  • Like 5

Share this post


Link to post
Share on other sites

Wow, that worked.

What causes this? Is there any way to prevent it / workaround?

  • Like 1

Share this post


Link to post
Share on other sites

A client made the pages, so I can't be 100% certain but they do like using their page-clone tools so it is highly likely it has something to do with it.

Share this post


Link to post
Share on other sites

What PW version?

That's why I'm not using clone tool. But see others using it all the time. This bug is not something you'll recognize unless you use has_parent, and I think there's lots of PW sites where this happens and nobody recognized it yet. It's that the parents table is broken for those. It's annoying cause once you stumble over it you have no idea whats happening, or you don't even will ever notice that some pages may not get returned.

  • Like 3

Share this post


Link to post
Share on other sites

The version was 2.3.0, I don't know if it affects newer versions.

This has most certainly affected other projects because I remember asking questions and being told has_parent was the answer, but no matter what I did, has_parent just wouldn't work. That project was using a lot of cloned pages, too..

I won't be using Page cloning any more as a safety pre-caution until we can get verification!

Share this post


Link to post
Share on other sites

2.3 is very old and surely there's bugs, but not sure it's fixed completely and it really has to do with clone tool. There was a attempt to fix issue with it, but I got a coworker running into it where this fix was in place already so it's a mistery.

Share this post


Link to post
Share on other sites

Hi everybody, I'm very glad I found this topic, thank you Soma for your answer. It worked like a charm.

I did run into the issue myself (while using version 2.5.3), my actions where the following:

I've cloned a page (including it's children), the page itself was found in it's parent but it's children weren't.

Example:

1001   =    Products

----- 1002   =   T-shirts

----- ------  1003  =  Small

----- ------  1004  =  Medium

----- ------  1005  =  Large

Duplicate *T-shirts* and rename it *Sweaters*

Tree looks like this:

1001   =    Products

----- 1002   =   T-shirts

----- ------  1003  =  Small

----- ------  1004  =  Medium

----- ------  1005  =  Large

----- 1006   =   Sweaters

----- ------  1007  =  Small

----- ------  1008  =  Medium

----- ------  1009  =  Large

find(has_parent=1001) returns:

1001,1002, 1003, 1004, 1005, 1006

The children of 1006 are missing.

I hope Ryan can reproduce the issue this way. 

  • Like 3

Share this post


Link to post
Share on other sites

Recently I've met the same issue at 2.6.4.

Looks like a super-critical bug as it compromises PW consistency...

If anybody knows - please share how to fix this. Finding&moving pages to/from is not a solution for db with over 100000 pages... I guess, some kind of repair script should be available. Thanks.

Share this post


Link to post
Share on other sites

The has_parent issues are not 100% fixed for 2.7.3 either. I've a fixer module in my installation, which does fix all the missing pages_parents rows every few hours.

Share this post


Link to post
Share on other sites
On 10/4/2017 at 2:57 PM, LostKobrakai said:

The has_parent issues are not 100% fixed for 2.7.3 either. I've a fixer module in my installation, which does fix all the missing pages_parents rows every few hours.

Hi, I just ran into this issue with 3.0.61. I have has_parent as a sub selector for a page reference field.

$categories = $pages->find("page_field=[has_parent=1234]");

It worked fine and at some point it stopped producing any results. It works if I move it out and do a two step filtering.
The only thing I did was to import more pages via Ryan's Import CSV module.

$parent = $pages->find("has_parent=1234);
$categories = $pages->find("page_field=$parent");

@LostKobrakai, would you mind sharing your module for fixing the parents table?
Thanks

Share this post


Link to post
Share on other sites

If it works with pulling the selector out it's a different issue. My problem were literally missing rows in the table, which would make both your examples fail.

Share this post


Link to post
Share on other sites

Just came across this issue in 3.0.62 and glad to find @Soma's workaround.

Not sure if it's caused by the clone function as the pages are created by a client, but highly possible.

Hope @ryan can fix this soon, maybe with @LostKobrakai's fixer module. Thx.

  • Like 1

Share this post


Link to post
Share on other sites

I also got this on 3.0.62 and @Soma's fix worked. I can't exactly tell what caused it. In my case has_parent only worked for the direct parent. Anything higher would fail to find anything.

Share this post


Link to post
Share on other sites

Still seems to happen with 3.0.96. Pages were bulk-imported via API, affects ~2 from more than 1000. Moving the parent page around fixed it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.