Skip to content

depends_on property fails in nested List+Array #3

Description

@JonasHoelscher

If the dsch schema looks like this

Comp(
   {
      "channel_1": Lt(Ar(
         dtype='float', unit='V', depends_on='channel_2')),
      "channel_2": Lt(Ar(
          dtype='float', unit='V', depends_on='channel_1')),
   }
)

When running the save() function an exception is thrown:
AttributeError: 'List' object has no attribute 'channel_2'

This error does not occur when the validation is skipped: By using save(force=True).

Possible cause:
The problem is that the validation does only look at the parent node and when the Array inside of the List has a depends_on property it will check the parent node, in this case the list, if it has an item called "channel_2".

This can be seen in dsch/data.py:

def validate(self):
        """Validate the node value against the schema node specification.

        If validation succeeds, the method terminates silently. Otherwise, an
        exception is raised.

        Raises:
            dsch.exceptions.ValidationError: if validation fails.
        """
        if self._storage is None:
            return
        independent_values = []
        node_names = self.schema_node.depends_on or []
        for node_name in node_names:
            if node_name:
                independent_values.append(getattr(self.parent, node_name)
                                          .value)
        self.schema_node.validate(self.value, independent_values)

Where when the items are added to the independent_values list only the direct parent is taken.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions