Skip to content

Commit 3561a5c

Browse files
committed
Update get_target_str to fall back to object
1 parent 46556a2 commit 3561a5c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pystac/link.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,17 @@ def target(self, target: Union[str, "STACObject_Type"]) -> None:
191191
self._target_object = target
192192

193193
def get_target_str(self) -> Optional[str]:
194-
"""Returns this link's target as a string."""
195-
return self._target_href
194+
"""Returns this link's target as a string.
195+
196+
If a string href was provided, returns that. If not, tries to resolve
197+
the self link of the target object.
198+
"""
199+
if self._target_href:
200+
return self._target_href
201+
elif self._target_object:
202+
return self._target_object.get_self_href()
203+
else:
204+
return None
196205

197206
def __repr__(self) -> str:
198207
return "<Link rel={} target={}>".format(self.rel, self.target)

0 commit comments

Comments
 (0)