diff --git a/pystac/stac_object.py b/pystac/stac_object.py index 1a8a6e435..eb6422a93 100644 --- a/pystac/stac_object.py +++ b/pystac/stac_object.py @@ -408,9 +408,10 @@ def from_file(cls, href): # If this is a root catalog, set the root to the catalog instance. root_link = o.get_root_link() - if not root_link.is_resolved(): - if root_link.get_absolute_href() == href: - o.set_root(o, link_type=root_link.link_type) + if root_link is not None: + if not root_link.is_resolved(): + if root_link.get_absolute_href() == href: + o.set_root(o, link_type=root_link.link_type) return o @classmethod diff --git a/tests/test_item.py b/tests/test_item.py index 730062234..0155cfd42 100644 --- a/tests/test_item.py +++ b/tests/test_item.py @@ -50,3 +50,12 @@ def test_read_eo_item_owns_asset(self): assert len(item.assets) > 0 for asset_key in item.assets: self.assertEqual(item.assets[asset_key].owner, item) + + def test_self_contained_item(self): + m = TestCases.get_path('data-files/itemcollections/sample-item-collection.json') + with open(m) as f: + item_dict = json.load(f)['features'][0] + item_dict['links'] = [l for l in item_dict['links'] if l['rel'] == 'self'] + item = Item.from_dict(item_dict) + self.assertIsInstance(item, Item) + self.assertEqual(len(item.links), 1)