ropensci / ruODK

ruODK: An R Client for the ODK Central API
https://docs.ropensci.org/ruODK/
GNU General Public License v3.0
42 stars 13 forks source link

Error with form_list() after update of ruODK #145

Closed dpagendam closed 1 year ago

dpagendam commented 1 year ago

Hi,

We have an ODK Central server that we've had interacting with ruODK now for a couple of years. I just did an update of ruODK on my local machine and the forms_list() function seems to be throwing errors. The code I am running (from R version 4.1.2) is:

library(ruODK) library(stringr) library(tidyverse) library(sp) library(rgdal) library(SDraw)

setwd("~/")

Initialize the set up for ruODK

tz <- "Asia/Riyadh" ruODK::ru_setup( svc = "https://myserver.com/v1/projects/3/forms/MyProject.svc", un = "myusername" pw = "mypassword" tz = tz, verbose = TRUE, # great for demo or debugging, url="https://myserver.com", retries = 10, odkc_version = "1.0" )

Store arrays

forms <- form_list()

Unexpected behaviour

The error I am now receiving is:

forms <- form_list() Error in tidyr::unnest_wider(): ! Can't subset columns that don't exist. ✖ Column reviewStates doesn't exist. Run rlang::last_error() to see where the error occurred.

Not sure if this is a bug. If this isn't a bug, do you have any suggestions on how to get around this?

lognaturel commented 1 year ago

What version of Central are you running? I'm guessing it's the latest or at least 1.5 or greater?

reviewStates in form extended metadata was introduced in 1.5. It's possible ruODK can't handle it being there.

dpagendam commented 1 year ago

Hi lognaturel,

thanks for your response. To answer your question, I'm fairly sure that we are using ODK Central v1.0. The server was set up a few years ago now and has run very well so it hasn't been updated since then. I tried to ssh into it to find a text file in the install that might give me the exact version but couldn't locate one. There is also no version number on the GUI interface for our installation.

The ODK Central server has been running very well with ruODK up until I updated my ruODK installation yesterday :-(

Please let me know if I can provide any further information or if you have any suggestions to fix things at my end.

dpagendam commented 1 year ago

Also, not sure if it helps but I tried with another machine that is running ruODK 0.9.10 under R4.0.5 and this can't still talk to our ODK Central server without a problem.

florianm commented 1 year ago

Hi @dpagendam, you see this error because the field in question was only added to Central in a newer version.

I'll take a look at this and will make ruODK robust against a missing review_state.

lognaturel commented 1 year ago

@dpagendam we highly encourage you to stay up to date with Central updates. Each release has important security patches. v1.0 is from August 2020.

That said, I do think there's an interesting question of how clients should handle additive API changes. Ideally they would be robust to them as you say, @florianm, but it may not always be realistic. In general, have you tried to make it so? When a response is expanded, do you typically create tests for with and without the new bit?

florianm commented 1 year ago

@lognaturel ruODK handles breaking changes via the environment variable ODKC_VERSION. See vignette setup. ruODK then toggles code paths depending on that variable (e.g., form schema).

Non-breaking changes such as added variables should be handled graciously - I'm working my way through the codebase to catch them all, personal bandwidth permitting. Bug reports do help here and are welcome!

Ideally, I'd have an array of test servers running the last few major versions we can expect ODK users to have in production to run my unit tests against, but currently I'm running them against the ODK Central server of my previous job. I still co-maintain that server and update it periodically to the latest version. I don't have access to any really outdated Central server.

@dpagendam this should be fixed in ruODK v1.4.0 - can you test this carefully? The new release bumps R (4.1) and package dependencies to keep up with the tidyverse.

dpagendam commented 1 year ago

Hi Florian, thanks for looking into this issue. I've just done a retest and am still hitting a snag connecting to the old ODK Central server after reinstalling ruODK 1.4.0 from Github. I am however getting a different error message after calling forms_list() under the same workflow as above:

forms <- form_list() Error in ru_msg_abort(): ! ✖ Missing ODK Central username. ru_setup()? Run rlang::last_error() to see where the error occurred. Warning message: ⚠ No default ODK Central username set. ru_setup()?

This was with a fresh install of ruODK and all dependencies under R version 4.1.3

Thanks again.

florianm commented 1 year ago

Hi Dan (@dpagendam), thanks for testing this so quickly!

One my end the test suite runs fine (which needs credentials), and I can run "form_list()" against my own Central server. This makes me assume that ruODK's settings and credential handling weren't broken with the latest changes.

Have you set up ruODK as per the "setup" vignette? You can use either of

Does ruODK::ru_settings() show any "Default ODK Central Username"?