__LZgetNodes: p is null in Datapath

While slaving away on a recent data-intensive Laszlo project, I happened across the following error:

INFO: __LZgetNodes: p is null in Datapath for container  name: c  id: c

Great - another cryptic error message. I’ll spare you the link by link Googlechase and code archealogy that ensued and do what you wish your linear algebra tutor would do: just tell you the right answer.
It turns out that the problem was in the following event handler:

<handler name="ondata">
 util.setAttributeIfDefined(this, "height", Number(datapath.xpathQuery("project/@video_height"))); 
 util.setAttributeIfDefined(this, "width", Number(datapath.xpathQuery("project/@video_width"))); 
</handler>

As I discovered, I was attempting to access a datapath that had yet to be linked to a data set. Note to Laszlo Systems: Could we get a bit of contextual help here? Like we’re spoiled with when we access a non-existent attribute? You know, like so:

hello.lzx:2:20: attribute "size" not allowed at this point; ignored 
hello.lzx:2:20: found an unknown attribute named "size" on element "text", however there is an attribute named "fontsize" on class "text", did you mean to use that?

The Solution

Make sure you’ve actually got a data set associated with the datapath before you use the datapath. The easiest way to do this is to use an ondata event handler instead of oninit, onload, or any of their non-data aware brethren.

4 Responses

  1. simoncpu Says:

    I spent hours racking my brain why a simple call to this.datapath.getNodeText() gives me “p is null in Datapath”, even though it works inside . Thank you very much for this tip. My code works fine now! =)

    [ simon.cpu ]

  2. ben shine Says:

    ROTFL! Despite being a a member of the OL team when this warning emerged, I never understood it, either. Now I’m working on a OL app for a client, and the first answer in my googlechase was this entry. Way to go!

  3. Tim Says:

    I actually just ran into this error and it turns out that the simple fix was moving my view that generated the error out of a library file and into the main file — I changed nothing else.

    WTF? :)

  4. admin Says:

    Hi Tim,

    It’s possible that moving the view out of the library fixed the issue due to non-deterministic execution. In other words, moving the view caused it to load at a slightly different time in program execution which was (apparently) a time when the datapath had been linked with a data set. It’s good to know that your code is working! However, if you want to ensure that it will *always* work as expected, you might want to wrap the code’s initialization inside of an ondata event handler as described above.

    Cheers! :)
    -Rich

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.