Skip to content
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

fix bug in make_absolute_href #94

Merged
merged 4 commits into from
May 22, 2020
Merged

fix bug in make_absolute_href #94

merged 4 commits into from
May 22, 2020

Conversation

simonkassel
Copy link
Collaborator

I was getting an error (stack trace below) running the tutorial notebook. Looks like PySTAC wasn't able to convert an item to a python dict if it didn't have a self href defined. This PR modified make_absolute_href to fix this issue, returning None rather than throwing an error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-8fc29b8a3af9> in <module>
      1 import json
----> 2 print(json.dumps(item.to_dict(), indent=4))

~/.local/lib/python3.6/site-packages/pystac/item.py in to_dict(self, include_self_link)
    178             'geometry': self.geometry,
    179             'bbox': self.bbox,
--> 180             'links': [l.to_dict() for l in links],
    181             'assets': assets
    182         }

~/.local/lib/python3.6/site-packages/pystac/item.py in <listcomp>(.0)
    178             'geometry': self.geometry,
    179             'bbox': self.bbox,
--> 180             'links': [l.to_dict() for l in links],
    181             'assets': assets
    182         }

~/.local/lib/python3.6/site-packages/pystac/link.py in to_dict(self)
    191         d = {'rel': self.rel}
    192 
--> 193         d['href'] = self.get_href()
    194 
    195         if self.media_type is not None:

~/.local/lib/python3.6/site-packages/pystac/link.py in get_href(self)
    109                 href = make_relative_href(href, self.owner.get_self_href())
    110         else:
--> 111             href = self.get_absolute_href()
    112 
    113         return href

~/.local/lib/python3.6/site-packages/pystac/link.py in get_absolute_href(self)
    127 
    128         if self.owner is not None:
--> 129             href = make_absolute_href(href, self.owner.get_self_href())
    130 
    131         return href

~/.local/lib/python3.6/site-packages/pystac/utils.py in make_absolute_href(source_href, start_href, start_is_dir)
     94         start_is_dir = True
     95 
---> 96     parsed_source = _urlparse(source_href)
     97     if parsed_source.scheme == '':
     98         if not _pathlib.isabs(parsed_source.path):

~/.local/lib/python3.6/site-packages/pystac/utils.py in _urlparse(href)
     16     """
     17     parsed = urlparse(href)
---> 18     if parsed.scheme != '' and href.lower().startswith('{}:\\'.format(parsed.scheme)):
     19         return URLParseResult(scheme='',
     20                               netloc='',

AttributeError: 'NoneType' object has no attribute 'lower'

@simonkassel simonkassel requested a review from lossyrob May 12, 2020 17:25
@lossyrob lossyrob merged commit bc27250 into develop May 22, 2020
@lossyrob lossyrob deleted the sjk/fix-bugs-in-tutorial branch June 20, 2020 22:14
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.

2 participants