growthcharts / james

Joint Automatic Measurement and Evaluation System (JAMES)
https://growthcharts.org/james/
GNU Affero General Public License v3.0
3 stars 0 forks source link

Server error (rq1, convert_tgt_chartadvice): is.list(x) is not TRUE # In call: # timedata(tgt) #19

Closed stefvanbuuren closed 8 months ago

stefvanbuuren commented 1 year ago

This error occurs in JAMES 1.5.4 and earlier when JAMES cannot find the input data. The most typical causes are:

Replication

Data to upload

{"Format":"3.0","organisationCode":1234,"reference":"Maria","clientDetails":[{"bdsNumber":19,"value":"2"},{"bdsNumber":20,"value":"20181011"},{"bdsNumber":82,"value":189},{"bdsNumber":91,"value":"1"},{"bdsNumber":110,"value":990},{"bdsNumber":238,"value":1670},{"bdsNumber":240,"value":1900}],"clientMeasurements":[{"bdsNumber":235,"values":[{"date":"20181111","value":380},{"date":"20181211","value":435}]},{"bdsNumber":245,"values":[{"date":"20181011","value":990},{"date":"20181111","value":1250},{"date":"20181211","value":2100}]},{"bdsNumber":252,"values":[{"date":"20181111","value":270},{"date":"20181211","value":305}]}],"nestedDetails":[{"nestingBdsNumber":62,"nestingCode":"01","clientDetails":[{"bdsNumber":63,"value":"19950704"}]},{"nestingBdsNumber":62,"nestingCode":"02","clientDetails":[{"bdsNumber":63,"value":"19901202"}]}]}
# request_site_methods.R
#
# Issue 23okt2023, AS
# Server error (rq1, convert_tgt_chartadvice): is.list(x) is not TRUE
# In call:
#   timedata(tgt)

library(jamesclient)
fn <- path.expand("~/Package/james/notes/Voorbeelddossier.txt")
host <- "https://james.groeidiagrammen.nl"
js <- read_json_js(fn)

# Create site: upload/data and manually construct URL (OK)
# Method 1
r1 <- james_post(host = host, path = "data/upload/json", txt = js)
site_url1 <- file.path(host, paste0("site?session=", r1$session))
browseURL(site_url1)

# Create site: site/request, implicit upload, manually construct URL (errors)
# Method 2 (spawns data/upload session)
r2 <- james_post(host = host, path = "/site/request/json",
                 sitehost = host, txt = fn)
site_url2 <- file.path(host, paste0("site?session=", r2$session))
browseURL(site_url2)
# The problem is that r2$session points to the site/request session,
# not to the spawned data/upload session

# Correct way:
# Create site: by site/request with implicit upload (OK)
# The return value points to the spawned data/uploaded session
browseURL(r2$parsed)

# Create site: site/request, using session input from data/upload (OK)
# Method 3 (evades manual URL construction)
r3 <- james_post(host = host, path = "/site/request/json",
                 sitehost = host, session = r1$session)
browseURL(r3$parsed)

Conclusions:

stefvanbuuren commented 8 months ago

In JAMES 1.5.5, the error caused by browseURL(site_url2) is easy to diagnose from the "Meldingen" panel. It now informs the developer at which session location JAMES looks for the data, and that JAMES cannot find child data there.

In addition, some changes to the underlying R code were made that prevented the R error, and instead transformed these into warnings. The pop-up window is gone, and now the application falls back on the standard chart NJAH (since there are no data).