Skip to content

Conversation

@m-hau
Copy link
Contributor

@m-hau m-hau commented Oct 30, 2025

Fixes: #20670

Explicitly check that any related object field is a list, and that each related object is a dictionary, and trigger a validation error if this is not the case. This prevents these cases to result in a hard internal error to occur.

While testing I also found three other minor issues in the same code area, which I took the liberty to fix as well:

  • Related objects are no longer indexed by 0 in the validation errors, but now from 1 like the top-level objects ("records")
  • Related object validation errors now show the correct top-level object ("record") index
  • Change the "Object with ID x does not exist" error to use the same format and channel as all other validation errors

Please see the individual commit messages for more detailed information on each individual change.

m-hau added 4 commits October 30, 2025 13:33
Index related objects from 1 and not from 0, just like top-level objects.
Use the parent object index as record index, and its own index only on
the field name.
The related object fields are not covered by the form, so don't pass
any validation before trying to iterate over them and accessing their
elements. Instead of allowing a hard technical error to be raised,
explicitly check that it is indeed a list, and raise a normal validation
error if not.

The error message is chosen to be similar in format and wording to the
other existing validation errors. The used word "list" is quite
universal, and conveys the wanted meaning in the context of python,
json and yaml.
Elements of the "related objects list" are passed to the
`prep_related_object_data` function before any validation takes place,
with the potential of failing with a hard error. Similar to the "related
objects not list" case explicitly validate the elements general type,
and raise a normal validation error if it isn't a dictionary.

The word "dictionary" is used here, since it is python terminology, and
is close enough to yaml's "mapping". While json calls them "objects",
their key-value syntax should make it obvious what "dictionary" means
here.
@jnovinger jnovinger requested review from a team and bctiemann and removed request for a team October 30, 2025 12:56
Change this one special case to also use the same communication channel
(toast notification) and message format as all other validation errors.

The error message is kept mostly the same, just the index prefix is
removed. This allowed keeping and easily adjusting the existing
localizations of it.
@m-hau m-hau force-pushed the bugfix/related-object-validation branch from d3671b5 to fbe76ac Compare October 30, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Device (Type) Import is missing component data type validation

1 participant