fraymio / modis-tools

Tools for working with the MODIS API and MODIS data.
Apache License 2.0
22 stars 11 forks source link

feature/fix_061_err #32

Closed jamie-sgro closed 1 year ago

jamie-sgro commented 1 year ago

Description

The root cause only occurs while multithreading. The one_or_many_urls in download_from_urls() is of type class 'pydantic.networks.AnyUrl' and when we try to cast it to a list in the below code, we tell it to only type-cast if it’s of type class 'pydantic.networks.HttpUrl'. Again it’s only an issue in multithreaded runs because single threaded already returns a list of type pydantic.networks.AnyUrl . Noting once again that we’re still using the wrong type for the check

That’s why we were getting the error AttributeError: 'str' object has no attribute 'host' because we listified ‘http://*’ so for the first iteration, url == ‘h’

    @staticmethod
    def _coerce_to_list(
        possible_list: Union[Iterable[Any], Any], obj_type: Type[T]
    ) -> Iterable[T]:
        """Cast possible single object into list

        Args:
            possible_list (Union[Iterable[Any], Any]): Variable to be converted to a list
            obj_type (Type): The type of the item within the returned list.
                Even though `obj_type` isn't used in implementation, it's key in
                determining return type
        """
        if isinstance(possible_list, obj_type):
            possible_list = [possible_list]
        return possible_list

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

I ran it in debug mode and asserted that we were getting just 'h' for the url array and that the cast wasn't actually converting to a list

Checklist:

Next Steps

On behalf of the Modis Tools Dev Team, thank you for your hard work! ✨