Skip to content

Enforce strict param for get -- not working as expected  #14

@ericpan64

Description

@ericpan64

Describe the bug

Seems like strict isn't doing anything -- investigate and fix!

How To Reproduce

def deep_nested_list() -> list[dict[str, Any]]:
    return [
        {
            "patient": {
                "id": "abc123",
                "active": True,
                "ints": [1, 2, 3],
                "dict": {"char": "a", "inner": {"msg": "A!"}},
                "dicts": [
                    {"num": 1, "text": "one", "inner": {"msg": "One!"}},
                    {"num": 2, "text": "two", "inner": {"msg": "Two!"}},
                ],
            }
        },
        {
            "patient": {
                "id": "def456",
                "active": False,
                "ints": [4, 5, 6],
                "dict": {"char": "b", "inner": {"msg": "B!"}},
                "dicts": [
                    {"num": 3, "text": "three", "inner": {"msg": "Three!"}},
                    {"num": 4, "text": "four", "inner": {"msg": "Four!"}},
                ],
            }
        },
        {
            "patient": {
                "id": "ghi789",
                "active": True,
                "ints": [7, 8, 9],
                "dict": {"char": "c", "inner": {"msg": "C!"}},
                "dicts": [
                    {"num": 5, "text": "five", "inner": {"msg": "Five!"}},
                    {"num": 6, "text": "six", "inner": {"msg": "Six!"}},
                ],
            }
        },
        {
            "patient": {
                "id": "jkl101112",
                "active": True,
                # 'ints' is deliberately missing
                "dict": {"char": "d", "inner": {"msg": "D!"}},
                # `dicts` is deliberately len=1 instead of len=2
                "dicts": [{"num": 7, "text": "seven", "inner": {"msg": "Seven!"}}],
            }
        },
    ]

l = deep_nested_list()

from pydian import get
# This will fail because it should be: `[*].patient.dict.inner.msg`
# We expect an error thrown because it's a `strict` call
get(l, "[*].dict.inner.msg", apply=" ".join, strict=True)

Expected behavior

Exception if something is missing

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions