Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deepcopy Asset.extra_fields when cloning #826

Merged
merged 4 commits into from
Jun 23, 2022

Conversation

duckontheweb
Copy link
Contributor

@duckontheweb duckontheweb commented Jun 8, 2022

Related Issue(s):

Description:

Uses deepcopy on Asset.extra_fields when cloning so that mutating the cloned Asset's extra fields does not mutate the original asset.

PR Checklist:

  • Code is formatted (run pre-commit run --all-files)
  • Tests pass (run scripts/test)
  • Documentation has been updated to reflect changes, if applicable
  • This PR maintains or improves overall codebase code coverage.
  • Changes are added to the CHANGELOG. See the docs for information about adding to the changelog.

@duckontheweb duckontheweb requested review from gadomski and m-mohr June 8, 2022 09:56
duckontheweb added a commit to duckontheweb/pystac that referenced this pull request Jun 8, 2022
@duckontheweb duckontheweb force-pushed the fix/820-asset-clone branch from 2637a20 to 50a3886 Compare June 8, 2022 10:00
@m-mohr
Copy link
Contributor

m-mohr commented Jun 8, 2022

Thank you @duckontheweb I'd also be fine with a shallow copy of Asset.extra_fields because that is what the documentation says, but also fine with a deep copy if documented properly.

@duckontheweb
Copy link
Contributor Author

Thank you @duckontheweb I'd also be fine with a shallow copy of Asset.extra_fields because that is what the documentation says, but also fine with a deep copy if documented properly.

@m-mohr Which documentation are you referring to here? The Asset.clone docs just say "Clones this asset.", which seems vague enough to cover both cases. I'll update that to be more specific, but is there another place where it specifically suggests we're doing a shallow copy?

@m-mohr
Copy link
Contributor

m-mohr commented Jun 9, 2022

Oh yeah, sorry, I was confusing this with the description of clone for Items/Collections...

@duckontheweb
Copy link
Contributor Author

I updated the Asset.clone docs and added a regression test to be sure Asset.roles is also not mutated on clones.

@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2022

Codecov Report

Merging #826 (696ded3) into main (0f308cd) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #826      +/-   ##
==========================================
+ Coverage   94.33%   94.34%   +0.01%     
==========================================
  Files          83       83              
  Lines       11898    11923      +25     
  Branches     1389     1390       +1     
==========================================
+ Hits        11224    11249      +25     
  Misses        495      495              
  Partials      179      179              
Impacted Files Coverage Δ
pystac/asset.py 86.11% <100.00%> (ø)
tests/test_item.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f308cd...696ded3. Read the comment docs.

@duckontheweb duckontheweb merged commit a6fffa5 into stac-utils:main Jun 23, 2022
@duckontheweb duckontheweb deleted the fix/820-asset-clone branch June 23, 2022 15:29
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.

Asset: clone() doesn't clone extra_fields
4 participants