review_tools complains about netlink_driver having a string value in snap declaration

Bug #1947612 reported by Daniel Manrique
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
review-tools
Fix Released
Undecided
Emilia Torino

Bug Description

This plug declaration :

{
  "allow-auto-connection": [
    {
      "slot-snap-id": [
        "whatever"
      ],
      "slot-names": [
        "netlink-foo"
      ],
      "slot-attributes": {
        "family": "24",
        "family-name": "a-family"
      },
      "plug-attributes": {
        "family-name": "$SLOT(family-name)"
      },
      "on-store": [
        "what-nice-store"
      ]
    }
  ]
}

and a snap with this in the snap.yaml:

slots:
  netlink-foo:
    interface: netlink-driver
    family: 24
    family-name: a-family

results in review-tools complaining as follows:

- declaration malformed (wrong type '24' for attribute 'family') declaration-snap-v2_valid_plugs (netlink-driver, allow-auto-connection_slot-attributes)

Looking at review-tools' interface_attribs I think review-tools wants the value in the snap-declaration to be an integer, but if I try to change the snap-declaration to:

      "slot-attributes": {
        "family": 24, <-------------- Making this an int
        "family-name": "a-family"
      },

then I can't even save the snap declaration:

netlink-driver must be a json-serialized dict. Dicts and lists are allowed as values, scalar values must be strings.

Does review-tools need to also (or instead) accept a string for "family"?

Related branches

Revision history for this message
Daniel Manrique (roadmr) wrote :

Apologies, looks like that lateral validation is done in the Snap Store dashboard code, this is applied to the dictionary and it clearly will barf on anything that's not a list, dict or string (lists and dicts must additionally also contain only lists, dicts or strings themselves).

def _valid_items(items):
        is_valid = True
        # items must be strings, or (lists or dicts) of items
        for item in items:
            is_valid = (
                isinstance(item, basestring)
                or (isinstance(item, list) and _valid_items(item))
                or (isinstance(item, dict) and _valid_items(item.values()))
            )
            if not is_valid:
                raise ValidationError(error_msg)
        return is_valid

Revision history for this message
Samuele Pedroni (pedronis) wrote :

For clarify _valid_items is just a pre-check. The assertion code and the assertion service themselves would return an error on an int header as well. That is by design.

Changed in review-tools:
assignee: nobody → Emilia Torino (emitorino)
Revision history for this message
Emilia Torino (emitorino) wrote :
Changed in review-tools:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.