Metadata validation errors do not identify which value failed
- Dominant language
- Python
- Stars
- 26
- Forks
- 21
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 15
Description
On a dandiset landing page, a failed metadata validation currently shows only the top-level field and the raw pydantic message. For https://dandiarchive.org/dandiset/000981/draft the entire error reads:
```
contributor: String should match pattern '^([\w\s\-\.']+),\s+([\w\s\-\.']+)$'
```
That dandiset has 15 contributors, and nothing in the message says which one is wrong or what is wrong with it. To find it I had to fetch the metadata and re-run the regex myself, which turned up the contributor at index 9, `"Yemini Eviatar"`, missing the comma between the family name and the given name.
The information needed is available, it is just discarded on the way to the database. `dandischema` reports the error as:
```json
{
"type": "string_pattern_mismatch",
"loc": ["contributor", 9, "Person", "name"],
"msg": "String should match pattern '^([\\w\\s\\-\\.']+),\\s+([\\w\\s\\-\\.']+)$'",
"input": "Yemini Eviatar"
}
```
`_encode_pydantic_error` in `dandiapi/api/services/metadata/__init__.py` keeps only `loc[0]` and ignores `input`, so both the position within the list and the offending value are lost before the error is stored. `_encode_jsonschema_error` already keeps the full path, but it likewise drops the instance that failed.
I would propose keeping the full `loc` as a dotted path, and carrying the offending value through to the UI when it is a simple scalar. The error above would then read something like:
```
contributor.9.Person.name: String should match pattern '^([\w\s\-\.']+),\s+([\w\s\-\.']+)$'
value: "Yemini Eviatar"
```
Container values, a whole contributor object for instance, would be omitted, since they are large and the path already identifies them.
Contributor guide
No contributing guide indexed for this repository
Research direction
Read _encode_pydantic_error and _encode_jsonschema_error in dandiapi/api/services/metadata/__init__.py, then trace how their stored errors reach the UI. Verify that paths retain the full location and simple scalar inputs are carried through, while container values are omitted; the displayed error should identify the failing contributor and value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100