-
Notifications
You must be signed in to change notification settings - Fork 123
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
Casting root Catalog to Catalog type interferes with pystac-client Client class #410
Comments
This doesn't necessarily need to be changed in PySTAC, because pystac-client could just redefine the I think in general it's not good practice to force cast the returned object from a factory function, as it means any subclass won't be able to use those functions. |
Looks like I was premature in my conclusion. Casting to Catalog doesn't seem to affect the current object, only the root it points to (so it's a deepcopy?). The problem is actually several lines up where these lines:
were replaced with the general function
which doesn't call the current class constructor and instead can only create STAC objects defined in PySTAC. It should be something like
|
Since The only other way I can see to fix this is to add something like an optional def stac_object_from_dict(
d: Dict[str, Any],
href: Optional[str] = None,
root: Optional["Catalog"] = None,
typ: Optional[STACObject] = None,
) -> "STACObject":
if typ is not None:
return typ.from_dict(d, href=href, root=root, migrate=False # ...or should migrate=True?
# Existing logic here... This may also be a good chance to consolidate and simplify some of that code. |
There is one case where STACObject is not an abstract class, and that is when classmethod functions are called directly as members of the class rather than an instantiated object. This is what happens when the To call Its easy enough to redefine a higher level functions, but a main takeaway is that creating a StacIO subclass is rather complicated, and it's not really clear what functions should be overridden in which cases since there are so many nested functions....the above doesn't even include the super() function calls(). I don't even know if the right thing has been done in the StacApiIO implementation for pystac-client. Everything works, and I don't want to derail the great momentum here, but it may be stepping back and looking at the IO approach to see if some functionality can be consolidated. |
Yes, thanks, I was thinking more a out how that would play out in the various I completely agree with the broader point here. It does seem like we need to re-examine the IO approach and make sure we're supporting reasonable inheritance patterns. |
@matthewhanson Does #451 close this, or are there additional changes that are needed? |
Closed via #451 |
The pystac-client Client class inherits from Catalog. In the latest version some logic was updated so that when it is read from a file (pystac-client uses from_file to initially open a root API), it sees that it is a root catalog and casts itself to a Catalog.
See here:
https://github.com/stac-utils/pystac/blob/main/pystac/stac_object.py#L484
The .from_file is the most immediate issue. There is casting to Catalog in other cases, such as if you item.get_root() it casts it to a catalog, but this didn't work before anyway, because PySTAC resolves STAC object links with logic that doesn't know about pystac-client's
Client
class.The text was updated successfully, but these errors were encountered: