Skip to content

ValueError: dictionary update sequence element #0 when using dict on a FeatureCollection #172

Closed
@rsemlal-murmuration

Description

@rsemlal-murmuration

Description

We have an error ValueError: dictionary update sequence element #0 has length X; 2 is required raised when using dict() on a valid instance of FeatureCollection.

How to reproduce

from geojson_pydantic import FeatureCollection

fc = FeatureCollection.model_validate({'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'properties': {}, 'geometry': {'type': 'Point', 'coordinates': [1, 2]}}]})

dict(fc) # <-- here

Expected

The call to dict should return a dict

Observed

The call to dict raises a ValueError

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: dictionary update sequence element #0 has length 5; 2 is required

Why is this an issue

We are using FeatureCollection as an input parameter type for a Prefect flow.

It looks something like this

# Flow definition
@flow(name="my_flow")
async def my_flow(area: FeatureCollection):
   return "yes"

my_flow(....) # Flow usage

It turns out that Prefect, since version 3.2.16 we believe, start applying a dict on flows input parameters if these parameters are Pydantic models (see here)

Since the dict fails on FeatureCollections, it makes unusable in this context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions