Skip to content

Validation allows more type promotion than the evaluator #315

@nsmith-

Description

@nsmith-

For example, the correction

{
  "schema_version": 2,
  "corrections": [
    {
      "name": "hi",
      "version": 2,
      "output": { "name": "hi", "type": "real" },
      "inputs": [{ "name": "blah", "type": "int" }],
      "data": {
        "nodetype": "category",
        "input": "blah",
        "content": [{ "key": "a", "value": "3.0" }]
      }
    }
  ]
}

has a content that should be a float but pydantic will happily validate and type-promote a string, e.g.

parsed = cs.CorrectionSet.model_validate_json(data)
print(parsed.corrections[0].data)

produces

nodetype='category' input='blah' content=[CategoryItem(key='a', value=3.0)] default=None

A similar issue is the source of the TODO in

# TODO: this is not detected by the pydantic model yet
hard_json = '{"schema_version":2, "corrections": [{"name": "hi", "version": 2, "output": {"name": "hi","type": "real"}, "inputs": [{"name":"blah", "type": "int"}], "data": {"nodetype": "category", "input": "blah", "content": [{"key": "a", "value": 3.0}]}}]}'

A solution could either:

  • Do the same type promotion inside the C++ evaluator, or
  • Configure pydantic to treat such cases as errors with strict mode

A potential workaround (or at least mechanism to catch such cases) in the correction validate CLI is to also construct an evaluator from the parsed model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions