"List of bases on invalid base" response is broken for charms with default track and no `latest` track

Bug #2018301 reported by Daniel Manrique
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snap Store Server
Fix Released
High
Shane M. Pelletier

Bug Description

When Juju does the initial "discovery" request to see which bases are available for a charm, it uses a bogus base. Charmhub then replies with an "invalid-charm-base" response showing the available bases. Example:

curl -XPOST -s https://api.charmhub.io/v2/charms/refresh -H 'Content-type: application/json' -d '{ "context": [], "actions": [{"name": "nginx-ingress-integrator", "base": {"name": "NA", "channel": "NA", "architecture": "amd64"} , "channel": "stable" , "action": "install", "instance-key": "a-test"}]}' | jq .

{
  "error-list": [],
  "results": [
    {
      "charm": null,
      "error": {
        "code": "invalid-charm-base",
        "extra": {
          "default-bases": [
            {
              "architecture": "amd64",
              "channel": "20.04",
              "name": "ubuntu"
            }
          ]
        },
        "message": "Instance key 'a-test' invalid 'base' in 'install' for charm_id=aQVXlrbsLWBTiAiQF0lilvUFolDOpKaE name=nginx-ingress-integrator"
      },
      "id": "aQVXlrbsLWBTiAiQF0lilvUFolDOpKaE",
      "instance-key": "a-test",
      "name": "nginx-ingress-integrator",
      "released-at": null,
      "result": "error"
    }
  ]
}

However, for a charm that has the following configuration:
1) A non-latest track
2) Said track is set as the default track
3) `latest` is closed

the response is revision-not-found instead, which confuses Juju and makes it say there is no revision to install.

I think the code that handles the invalid base and sends invalid-charm-base is unaware of default tracks, which should be preferred if they exist. Usual behavior:

1) if `latest` is specified, then use that (this will rightfully fail because there is no latest track).

2) if latest is not given, in the case of this charm which has a default track, return data for the *default* track instead.

3) (for completeness) If latest is not given, and the charm does NOT have a default track, then use "latest" by default (this is typical behavior fwiw).

The confusing thing for this charm is as mentioned that it has a default track *and* latest has been closed.

$ curl -XPOST -s https://api.charmhub.io/v2/charms/refresh -H 'Content-type: application/json' -d '{ "context": [], "actions": [{"name": "mysql", "base": {"name": "NA", "channel": "NA", "architecture": "amd64"} , "channel": "stable" , "action": "install", "instance-key": "a-test"}]}' | jq .
{
  "error-list": [],
  "results": [
    {
      "charm": null,
      "error": {
        "code": "revision-not-found",
        "extra": {
          "releases": [
            {
              "base": {
                "architecture": "amd64",
                "channel": "22.04",
                "name": "ubuntu"
              },
              "channel": "8.0/stable"
            },
            {
              "base": {
                "architecture": "amd64",
                "channel": "22.04",
                "name": "ubuntu"
              },
              "channel": "8.0/candidate"
            },
            {
              "base": {
                "architecture": "amd64",
                "channel": "22.04",
                "name": "ubuntu"
              },
              "channel": "8.0/beta"
            },
            {
              "base": {
                "architecture": "amd64",
                "channel": "22.04",
                "name": "ubuntu"
              },
              "channel": "8.0/edge"
            }
          ]
        },
        "message": "No revision was found in the Store."
      },
      "id": "F8CtvgcznoeRSupRrY2uEa67oQtBTF7x",
      "instance-key": "a-test",
      "name": "mysql",
      "released-at": null,
      "result": "error"
    }
  ]
}

For more info, this is the actual request Juju makes :

curl -XPOST -s https://api.charmhub.io/v2/charms/refresh -H 'Content-type: application/json' -d '{"context":[],"actions":[{"action":"install","instance-key":"ba0ea644-b34a-4a8c-83eb-4f3930ac8e83","name":"mysql","channel":"stable","base":{"architecture":"amd64","name":"NA","channel":"NA"}}],"fields":["bases","config-yaml","download","id","license","metadata-yaml","name","publisher","resources","revision","summary","type","version"]}

Daniel Manrique (roadmr)
Changed in snapstore-server:
importance: Undecided → High
status: New → Triaged
status: Triaged → Confirmed
Revision history for this message
Alex Lutay (taurus) wrote :

Dear Daniel, please check https://chat.charmhub.io/charmhub/pl/ct994gu8ybdjxx7cthjiicpmcw

If possible, please rise the priority for this bugreport. Thank you in advance!

Changed in snapstore-server:
status: Confirmed → Fix Committed
assignee: nobody → Shane M. Pelletier (shanepelletier)
Changed in snapstore-server:
status: Fix Committed → 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.