Skip to content

Relationship data generator is invoked more than once if data is empty #252

Open
@lindyhopchris

Description

@lindyhopchris

I've been getting this error:

Exception: Cannot traverse an already closed generator
src/Parser/RelationshipData/RelationshipDataIsCollection.php:132

It only occurs when relationship data is empty. The cause of the bug is these lines here:
https://github.com/neomerx/json-api/blob/master/src/Parser/RelationshipData/RelationshipDataIsCollection.php#L130-L131

As it does not assign an empty array to $this->parsedResources before iterating over the resource, the parsedResources property will remain null. Therefore when it is called a second time, there is no cache to use and the closed generator is used.

I'll submit a PR with a test reproducing the problem and a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions