Skip to content

should hydrate coerce None to an empty dictionary or list? #7

@mishaschwartz

Description

@mishaschwartz

The tests for pypgstac make it seem like the hydrate function is expected to be able to treat a None value as if it were an empty dictionary:

    def test_base_none(self) -> None:
        base_item = {"value": None}
        dehydrated = {"value": {"a": "b"}}
        hydrated = self.hydrate(base_item, dehydrated)
        assert hydrated == {"value": {"a": "b"}}

See the relevant code here: `https://github.com/stac-utils/pgstac/blob/6c569c0ee56bd9519ad947cbcaa8bfbcfade15bb/src/pypgstac/tests/hydration/test_hydrate.py#L241-L245

Right now, the hydrate function does not do that. Instead it tries to downcast the None value to a dict and raises an error since it can't do that:

hydraters/src/lib.rs

Lines 42 to 49 in d3946d3

if let Ok(item) = item.downcast::<PyDict>() {
if let Ok(base) = base.downcast::<PyDict>() {
hydrate_dict(base, item)?;
} else {
return Err(PyValueError::new_err(
"type mismatch: item is a dict, but the base was not",
));
}

Do we want to change the code here so that if item or base is None, we convert it to a dict or list? Or if not, we should update the tests in pgstac.

What do you think?

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