nextstrain / auspice

Web app for visualizing pathogen evolution
https://docs.nextstrain.org/projects/auspice/
GNU Affero General Public License v3.0
292 stars 162 forks source link

Sidecars don't work when changing dataset via the sidebar (under certain conditions) #1855

Open jameshadfield opened 3 weeks ago

jameshadfield commented 3 weeks ago

When changing between two datasets via the sidebar dropdown UI, each with a tip frequencies sidecar, we saw someone get a warning banner indicating a failure to normalise frequencies and the sidebar option is not available. The relevant code for the sidebar is:

https://github.com/nextstrain/auspice/blob/de94b72e155e7d386f1c82509727b422f0c6f99d/src/components/controls/frequency-normalization.js#L22-L32

and checkIfNormalizableFromRawData seems to always return true (!)

https://github.com/nextstrain/auspice/blob/de94b72e155e7d386f1c82509727b422f0c6f99d/src/util/processFrequencies.js#L62-L63

implying a race condition around this.props.frequencies.loaded && this.props.tree.loaded.

Reloading the page works as expected.

I don't have any reproducible datasets (have asked for them), and note that changing https://nextstrain.org/seasonal-flu/h3n2/ha/3y to 2y (via sidebar) works as expected. Perhaps it's dataset specific (hard to understand after skimming the relevant code) or using an old version of auspice (normalisation checking was removed in https://github.com/nextstrain/auspice/commit/7b9495b107517008ef5d1dca7466e83f3db2984a in 2001)

joverlee521 commented 3 weeks ago

I can reproduce locally by changing the dataset via one of the dropdowns that is not the last one, e.g. changing from http://localhost:4000/flu/seasonal/h1n1pdm/ha/12y to na via sidebar triggers the warning.

jameshadfield commented 3 weeks ago

This bug is only observed when using the Auspice server (i.e. not within nextstrain.org). Steps to reproduce:

  1. provision appropriate datasets
    nextstrain remote download nextstrain.org/seasonal-flu/h3n2/ha/2y
    nextstrain remote download nextstrain.org/seasonal-flu/h3n2/na/2y
    nextstrain remote download nextstrain.org/seasonal-flu/h3n2/ha/3y
  2. Within auspice, load seasonal-flu/h3n2/ha/2y
  3. Use the sidebar to change "ha" to "na".
  4. The error is shown and the entire frequencies panel is missing. The console has a more useful error: TypeError: rawJSON.pivots is undefined
jameshadfield commented 3 weeks ago

Notes from a briefly looking into this (have to jump to other things now):

In the above example, we use an incomplete URL to fetch the tip frequencies:

this.apiCalls.tipFrequencies = /charon/getDataset?prefix=seasonal-flu/h3n2/na&type=tip-frequencies

(note the missing "2y" from the path). The auspice server redirects to /charon/getDataset?prefix=/seasonal-flu/h3n2/na/2y and thus returns the main dataset JSON. Because this is a valid JSON, we don't have a fetch error and end up with a frequencies parsing error.

There seem to be two potential solutions: have the server redirect and respect the type query (I presume this is what nextstrain.org does, must check), or redesign how we formulate the api calls (addresses) for sidecars.

The server behaves the same way for root-sequence & measurements URLs, so these should also be tested.

jameshadfield commented 3 weeks ago

Nextstrain org redirect flow:

/charon/getDataset?prefix=seasonal-flu/h3n2/na&type=tip-frequencies is a 307 to /charon/getDataset?prefix=seasonal-flu/h3n2/na/2y&type=tip-frequencies

Auspice (localhost) is:

/charon/getDataset?prefix=seasonal-flu/h3n2/na&type=tip-frequencies is a 302 to charon/getDataset?prefix=/seasonal-flu/h3n2/na/2y