Skip to content

V2: get_target() while recursing items results in multiple instances for same object #1714

@tylanderson

Description

@tylanderson

Calling get_target() on a link (same link href, different object) while recursing through items (e.g. col.get_items()) will result in a new instance of that targeted object. This is a change from v1

An simplified example of this, adapted from stactools fixture (where get_parent() calls get_target()):

col = pystac.Collection.from_file(
        "tests/data-files/planet-disaster/collection.json"
)
for item in list(col.get_items(recursive=True)):
    parent = item.get_parent()
    print(f"Parent is {parent.id}: {id(parent)}")

will yield

Parent is hurricane-harvey-0831: 4512587968
Parent is hurricane-harvey-0831: 4599873760
Parent is hurricane-harvey-0831: 4512212864
Parent is hurricane-harvey-0831: 4512213728
Parent is hurricane-harvey-0831: 4512214640

where each item creates a new instance of the parent. This broke a test fixture where mutating the parent from one item updated the same instance that other items accessed.

I'm not sure if this behavior from v1 (cached) is what we want to keep for v2, but surfacing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions