mapillary / mapillary-python-sdk

A Python 3 library built on the Mapillary API v4 to facilitate retrieving and working with Mapillary data.
MIT License
37 stars 14 forks source link

Bug Report: Request detection with image key fails #132

Closed cbeddow closed 2 years ago

cbeddow commented 2 years ago

Describe the bug I request a detection with the image key, and the function fails.

To Reproduce Run the following:

data = mly.get_detections_with_image_id(image_id=1933525276802129)

Expected behavior This should return a list of detections for the image key specified

Screenshots

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_47044/4018995761.py in <module>
----> 1 data = mly.get_detections_with_image_id(image_id=1933525276802129)

C:\Python38\lib\site-packages\mapillary\utils\auth.py in wrapper(*args, **kwargs)
     58 
     59             # Return function called with arguments
---> 60             return f(*args, **kwargs)
     61 
     62         # Return wrapper

C:\Python38\lib\site-packages\mapillary\interface.py in get_detections_with_image_id(image_id, fields)
    226     """
    227 
--> 228     return detection.get_image_detections_controller(
    229         image_id=image_id,
    230         fields=fields,

C:\Python38\lib\site-packages\mapillary\controller\detection.py in get_image_detections_controller(image_id, fields)
     52     # Return results from the Adapter
     53     return GeoJSON(
---> 54         geojson=EntityAdapter().fetch_detections(
     55             identity=image_id,
     56             id_type=True,

C:\Python38\lib\site-packages\mapillary\models\api\entities.py in fetch_detections(self, identity, id_type, fields)
    170 
    171             # Store the URL as ...
--> 172             url = Entities.get_detection_with_image_id(
    173                 # .. extracted by setting image_id as id ...
    174                 image_id=str(identity),

C:\Python38\lib\site-packages\mapillary\config\api\entities.py in get_detection_with_image_id(image_id, fields)
    196         """
    197 
--> 198         fields = Entities.__field_validity(
    199             given_fields=fields,
    200             actual_fields=Entities.get_detection_with_image_id_fields(),

C:\Python38\lib\site-packages\mapillary\config\api\entities.py in __field_validity(given_fields, actual_fields, endpoint)
    342 
    343         # Converting the given_fields into lowercase
--> 344         given_fields = [field.lower() for field in given_fields]
    345 
    346         # Enforce the existence of 'geometry' in the given_fields

TypeError: 'NoneType' object is not iterable

Additional context If I add fields="captured_at", it gets a 200 but then tries to parse the text and finds "c". If I add fields=["captured_at"] if gets a 200 , but then says the dictionary changed size and fails.

cbeddow commented 2 years ago

Same problem with map features:

data=mly.get_detections_with_map_feature_id(map_feature_id=852766358956987).to_dict()
Rubix982 commented 2 years ago

Thanks for the issue! There is probably a problem with a default value somewhere, or the dict not being read correctly as the data type and thus resulting in a NoneType. I'll look at this sometime this week.

cbeddow commented 2 years ago

@Rubix982 did you get a chance to investigate this one?

Rubix982 commented 2 years ago

I assumed that None is the same as [] - I'm not sure why. Replacing the default arguments with [] instead of None works. I am not sure why this broke just now and not previously in August's release.

Also, a minor issue with format.py where a loop was deleting the same array it was traversing.