sat-utils / sat-search

A python client for sat-api
MIT License
189 stars 43 forks source link

Error when creating a Search with a datetime (RuntimeError: dictionary keys changed during iteration) #97

Closed dylnclrk closed 4 years ago

dylnclrk commented 4 years ago

Forgive me as I'm missing a bunch of background knowledge here, but I figured I'd raise this issue I encountered.

When creating a search like this (as guided by the example notebook):

>>> from satsearch import Search
>>> Search(bbox=[-110, 39.5, -105, 40.5], datetime='2018-02-01/2018-02-04', property=["eo:cloud_cover<5"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "…/satsearch/search.py", line 28, in __init__
    for k in self.kwargs:
RuntimeError: dictionary keys changed during iteration

I wonder if it's happening when we move the datetime entry over to time, since it doesn't seem to happen for searches that don't include the datetime keyword,

class Search(object):
    # …

    def __init__(self, **kwargs):
        """ Initialize a Search object with parameters """
        self.kwargs = kwargs
        for k in self.kwargs:
            if k == 'datetime':
                self.kwargs['time'] = self.kwargs['datetime']
                del self.kwargs['datetime'] # <--------- here?

Fwiw, I'm running python 3.8.4, I'm not sure what version(s) sat-search is tested against.

matthewhanson commented 4 years ago

@dylnclrk thanks for posting this. As you suggested, it seems that the problem is very likely with Python 3.8 which enforces not being able to change dictionary keys during iteration...it was always a bad idea to do it anyway, a new dictionary should have been made here.

However, I think it's a moot point now, because you must be using the most recently released version, 0.2.3, since the time query was moved to datetime in STAC and on the sat-search dev branch and 0.3.0-rc1 version, so this hack was no longer needed*

You can install the most recent released version, 0.3.0-rc1 with

$ pip install sat-search==0.3.0-rc1

however I'm also issuing a PR to make a final release after making some final updates to the notebook tutorial so tomorrow this should be available on PyPi as 0.3.0.