Skip to content

Flattener can attempt to call replace on a list #9

@amc-corey-cox

Description

@amc-corey-cox

In a recent PR for linkml-runtime. I encountered the following error in unflatten_from_csv.

        objs = []
        for row in r:
            nu_obj = {}
            for k, v in row.items():
                key_config = config.key_configs.get(k, None)
>               v = v.replace('\\n', '\n').replace('\\t', '\t')
                    ^^^^^^^^^
E               AttributeError: 'list' object has no attribute 'replace'

.venv/lib/python3.12/site-packages/json_flattener/flattener.py:355: AttributeError
----------------------------------------------------------- Captured log call ------------------------------------------------------------
WARNING  linkml_runtime.utils.csvutils:csvutils.py:37 Index slot or schema not specified
======================================================== short test summary info =========================================================
FAILED tests/test_loaders_dumpers/test_csv_tsv_loader_dumper.py::CsvAndTsvGenTestCase::test_table_model - AttributeError: 'list' object has no attribute 'replace'

It appears that our upstream processes can now pass a list object into this function where v.replace() get's called. At minimum, we should guard against the list call here but we may need to do something more intelligent if lists are passed, such as iterating through them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions