Skip to content

fix: preserve extra_fields in Link.clone - #1860

Merged
jsignell merged 2 commits into
stac-utils:mainfrom
mccalpink:fix/1856-link-clone-extra-fields
Nov 19, 2026
Merged

jsignell merged 2 commits into
stac-utils:mainfrom
mccalpink:fix/1856-link-clone-extra-fields

Conversation

@mccalpink

Copy link
Copy Markdown
Contributor

Related Issue(s):

Description:

Summary

Link.clone() drops extra_fields, so every clone()/full_copy() of an Item, Collection or Catalog (and ItemCollection.clone()) loses additional link fields.

Root cause

Link.clone() rebuilt the link from rel, target, media_type and title only, without passing extra_fields to the constructor. Both Catalog.clone() and STACObject.full_copy() copy links through Link.clone(), so any additional link fields (e.g. foo:bar) were lost.

Fix

Pass extra_fields=deepcopy(self.extra_fields) in Link.clone(). The deep copy keeps the clone independent from the original, the same approach as Asset.clone() and consistent with how Catalog.clone() already handles the catalog's own extra_fields.

Verification

Locally on Python 3.12. New tests (they fail on main, pass with the fix):

  • tests/test_link.py: test_clone_preserves_extra_fields, test_clone_does_not_share_extra_fields
  • tests/test_catalog.py: test_clone_link_extra_fields, test_full_copy_link_extra_fields

Commands and results:

  • pytest tests/test_link.py tests/test_catalog.py -k "clone_preserves or clone_does_not or clone_link_extra or full_copy_link_extra": 4 failed before the fix, 4 passed after
  • pytest: 1562 passed, 18 skipped
  • ruff check, ruff format --check, codespell and mypy --no-incremental on the changed files: clean

PR Checklist:

  • Pre-commit hooks pass (run pre-commit run --all-files) — ruff, ruff-format, codespell and mypy were run directly on the changed files; pyupgrade and doc8 were not run (no .rst changes)
  • Tests pass (run pytest)
  • Documentation has been updated to reflect changes, if applicable (not applicable; CHANGELOG is managed by release-please)
  • This PR maintains or improves overall codebase code coverage
  • This PR's title is formatted per conventional commits

This PR was prepared with AI assistance (Claude Code). I have reviewed the change and the test results.

Link.clone() rebuilt the link from rel, target, media_type and title only,
so extra_fields were dropped from every link of a Catalog.clone() or
Catalog.full_copy(). Deep-copy them into the clone so that the copy keeps
the fields without sharing mutable state with the original.
@gadomski
gadomski self-requested a review November 19, 2026 11:59

@gadomski gadomski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, thanks!

@gadomski
gadomski added this pull request to the merge queue Nov 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 19, 2026
@jsignell
jsignell enabled auto-merge November 19, 2026 18:22
@jsignell
jsignell added this pull request to the merge queue Nov 19, 2026
Merged via the queue into stac-utils:main with commit 924560a Nov 19, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Links are not correctly copied by Catalog.full_copy()

3 participants