-
Notifications
You must be signed in to change notification settings - Fork 122
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
Use root StacIO in Link.resolve_stac_object when possible #742
Comments
cc: @matthewhanson |
cc: @KennSmithDS |
@duckontheweb asking a few clarifying questions on the proposed change request.
|
Yes, sorry about that, I just corrected the original description.
Looking at this again, I think the simplest solution might be to add an else clause to this statement, something like: if self.owner is not None:
if isinstance(self.owner, pystac.Catalog):
stac_io = self.owner._stac_io
else:
root = self.owner.get_root()
if root is not None:
stac_io = root._stac_io I'm a little torn on whether we should overwrite |
@duckontheweb that's similar to the implementation I have on my local branch, but is there a possibility that even though if stac_io is None:
if self.owner is not None:
if isinstance(self.owner, pystac.Catalog):
stac_io = self.owner._stac_io
else:
stac_io = self.owner.get_root()._stac_io
else:
stac_io = pystac.StacIO.default() |
Yes, good point. I think changing that if stac_io is None:
if self.owner is not None:
if isinstance(self.owner, pystac.Catalog):
stac_io = self.owner._stac_io
else:
stac_io = self.owner.get_root()._stac_io
if stac_io is None:
stac_io = pystac.StacIO.default() Seems a little ugly, maybe there's a more concise way that I'm not seeing 🤷🏻 |
My instinct is to not overwrite, on the off chance that someone/somecode is relying on the passed in |
Seems like it needs one more guard, in the case that there is owner with no root set: if stac_io is None:
if self.owner is not None:
if isinstance(self.owner, pystac.Catalog):
stac_io = self.owner._stac_io
else:
owner_root = self.owner.get_root()
if owner_root is not None:
stac_io = owner_root._stac_io
if stac_io is None:
stac_io = pystac.StacIO.default() But otherwise that logic seems sound to me. |
Yeah, I agree, let's not overwrite it. It looks like @lossyrob 's suggestion covers everything. |
if stac_io is None:
if self.owner is not None:
if isinstance(self.owner, pystac.Catalog):
stac_io = self.owner._stac_io
else:
owner_root = self.owner.get_root()
if owner_root is not None:
stac_io = owner_root._stac_io
if stac_io is None:
stac_io = pystac.StacIO.default() @lossyrob @duckontheweb it appears with this code change, the PR is failing CI unit tests because of StackOverflow, i.e. maximum recursion depth is being reached.
I think this might be occurring when the
and
Is there a way to easily check if the root of |
@KennSmithDS just took a look - seems like the issue is that when resolving a root link, it shouldn't go looking for the owner's root - because that's what it's currently resolving! Avoiding the owner root check with: if stac_io is None:
if self.owner is not None:
if isinstance(self.owner, pystac.Catalog):
stac_io = self.owner._stac_io
elif self.rel != pystac.RelType.ROOT:
owner_root = self.owner.get_root()
if owner_root is not None:
stac_io = owner_root._stac_io
if stac_io is None:
stac_io = pystac.StacIO.default() passes tests. Made a suggestion on the PR with that change. |
This came up in the context of working with links in
pystac-client
, but I am opening this here since the potential fix would need to happen in PySTAC.Use-case
The following code creates a
pystac_client.Client
instance that will pass akey
query parameter containing an API key with every request:The
key
parameter is not sent becauseclient._stac_io
is not being used in the requests made byLink.resolve_stac_object
.Proposed Solution
The current method for determining which
StacIO
instance to use inLink.resolve_stac_object
is:root
argument is notNone
, useroot._stac_io
Link
has an owner and that owner is apystac.Catalog
, use that Catalog's_stac_io
(if it is notNone
)StacIO.default()
if none of the above resolve aStacIO
instanceI propose adding a step between 2 & 3 that uses
self.owner.get_root()._stac_io
if it is notNone
. It seems reasonable to assume that if aStacIO
instance is attached to a root catalog then all children of that catalog will want to use the sameStacIO
instance.The text was updated successfully, but these errors were encountered: