Skip to content

Make ExtensionManagementMixin.add_to idempotent #419

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

Merged
merged 2 commits into from
Jun 16, 2021

Conversation

duckontheweb
Copy link
Contributor

@duckontheweb duckontheweb commented Jun 8, 2021

Related Issue(s): #

Description:

pystac.extensions.base.ExtensionManagementMixin.add_to will only add the schema URI for the inheriting extension class if it is not already in the object's stac_extensions list.

I looked into making stac_extensions a set instead of a list, but the extra complexity to ensure that the set was properly serialized and deserialized did not seem worth the effort. If that seems like the better approach, I can explore it in more depth, though.

PR Checklist:

  • Code is formatted (run scripts/format)
  • Tests pass (run scripts/test)
  • 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 lossyrob and gadomski June 8, 2021 01:58
Copy link
Member

@gadomski gadomski left a comment

Choose a reason for hiding this comment

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

👍🏽 to keepin' it simple for now, and if we identify this as a performance bottleneck later we know how to proceed (seems unlikely).

@lossyrob
Copy link
Member

lossyrob commented Jun 8, 2021

We also talked about checking that the object to see if it has the extension on FooExtension.ext(...), and throwing if it didn't exist, and also adding a add_if_missing flag to that method to allow a one-liner to add the extension and get the extension object. Is that still a plan? If so, should that be tackled in another PR or added to this?

@duckontheweb
Copy link
Contributor Author

We also talked about checking that the object to see if it has the extension on FooExtension.ext(...), and throwing if it didn't exist, and also adding a add_if_missing flag to that method to allow a one-liner to add the extension and get the extension object. Is that still a plan? If so, should that be tackled in another PR or added to this?

I started to tackle that as part of this PR, but there's a wrinkle with how to handle that when extending an Asset with no owner, since it won't have any extension info associated with it. I figured I would work through that in comments on #370 and merge this in the meantime, but I'm also fine with keeping this open until that's resolved.

@duckontheweb duckontheweb added this to the 1.0.0-rc.1 milestone Jun 9, 2021
@duckontheweb
Copy link
Contributor Author

I figured I would work through that in comments on #370 and merge this in the meantime, but I'm also fine with keeping this open until that's resolved.

I will actually just implement that as part of this PR and we can get feedback on the approach that way. Probably easier than trying to discuss it in an issue.

@duckontheweb duckontheweb marked this pull request as draft June 10, 2021 19:05
@duckontheweb
Copy link
Contributor Author

@lossyrob Sorry to keep waffling on this, but I think it would be best to merge this and tackle #370 in a separate PR. There are some challenges around how and where to implement that exception and how to handle Asset instances without an owner that might be best to work out separately, and it probably doesn't make sense to hold up this change in the meantime.

@duckontheweb duckontheweb marked this pull request as ready for review June 16, 2021 00:36
@duckontheweb duckontheweb force-pushed the fix/369-idempotent-add-to branch from 9a9f6f1 to 77b5d97 Compare June 16, 2021 00:39
@codecov-commenter
Copy link

Codecov Report

Merging #419 (77b5d97) into main (e7d4bdc) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #419   +/-   ##
=======================================
  Coverage   90.67%   90.67%           
=======================================
  Files          40       40           
  Lines        5105     5106    +1     
=======================================
+ Hits         4629     4630    +1     
  Misses        476      476           
Impacted Files Coverage Δ
pystac/extensions/base.py 91.66% <100.00%> (+0.17%) ⬆️

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 e7d4bdc...77b5d97. Read the comment docs.

@duckontheweb duckontheweb merged commit 7f8e7aa into stac-utils:main Jun 16, 2021
@duckontheweb duckontheweb deleted the fix/369-idempotent-add-to branch June 16, 2021 14: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.

ExtensionManagementMixin.add_to should be idempotent
4 participants