Script filter not returning entity that was created in previous loop

We have a script that does the following:

  1. Takes the full URL of a page from an XML file and breaks all the slugs into an array.

For example:
Full URL: http://www.fibery.io/page1/page2/page3
Slug Array: page1, page2, page3

  1. Checks the first slug in the array to see if a Page with a matching “Parent Page” and “Page Path” field exists.

Parent Path is the following formula: If(IsEmpty([Parent Page]), “”, [Parent Page].[Page Path])
Page Path is the following formula: Parent Path + “/” + Slug

For example:
Loop 1:
Slug: page1
Parent Path:
Page Path: page1

Loop 2:
Slug: page2
Parent Path: page1
Page Path: page1/page2

Loop 3:
Slug: page3
Parent Path: page1/page2
Page Path: page1/page2/page3

  1. If no match is found, create new entity, and then loop on the next slug in the array.

We’re having an issue in Loop 2 and beyond, were no matches are being found for “Parent Path” even though we know the parent was created and linked in the previous loop.

Is this because we’re using formulas for our 2 path fiends and the formulas are not being generated quickly enough to be populated before the next entity search happens? Or is there another thing at play?

Probably this