rstudio / pins-r

Pin, discover, and share resources
https://pins.rstudio.com
Other
312 stars 63 forks source link

Offline pin access to rsconnect with new API #587

Closed slohr closed 1 year ago

slohr commented 2 years ago

It appears that the 1.0.0 API does not honor the "use_cache_on_failure" flag when reading a previously accessed pin while offline. In addition, now that you need to pass around a "board" object it fails at an earlier stage in the process.

Perhaps I'm not adapting my code properly to use this feature in the new API?

Note: Legacy API access to cached pins in rsconnect works when you're offline (see #423)

Test case:

board <- pins::board_rsconnect(
  auth="manual",
  server="https://connect.example.com",
  account="the_username_to_be_used",
  key = "An_API_key_in_Renviron",
  use_cache_on_failure = TRUE #forcing for testing
)

test data

my_test_data <- tibble::tribble(
  ~a, ~b, ~c,
  "a1", "b1", "c1",
  "a2", "b2", "c1"
)
my_test_data

Write with the new API

board %>% pins::pin_write(
  my_test_data, 
  "my_test_pin_data"
)

Now retrieve

board %>% pins::pin_read(
  "my_test_pin_data"
)

If you disconnect VPN or WiFi so that the URL is not accessible, you'll then get this error:

Error in curl::curl_fetch_memory(url, handle = handle) : Timeout was reached: [connect.alkahest.io] LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60

traceback

20.
curl::curl_fetch_memory(url, handle = handle)
19.
request_fetch.write_memory(req$output, req$url, handle)
18.
request_fetch(req$output, req$url, handle)
17.
request_perform(req, hu$handle$handle)
16.
httr::GET(board$url, path = path, query = query, auth, ...)
15.
rsc_GET(board, "v1/content", list(name = name$name))
14.
rsc_content_find(board, name)
13.
pin_meta.pins_board_rsconnect(board, name, version = version)
12.
pin_meta(board, name, version = version)
11.
pin_fetch.pins_board_rsconnect(board, name, version = version, ...)
10.
pin_fetch(board, name, version = version, ...)
9.
pins::pin_read(., "my_test_pin_data")
8.
function_list[[k]](value)
7.
withVisible(function_list[[k]](value))
6.
freduce(value, `_function_list`)
5.
`_fseq`(`_lhs`)
4.
eval(quote(`_fseq`(`_lhs`)), env, env)
3.
eval(quote(`_fseq`(`_lhs`)), env, env)
2.
withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1.
board %>% pins::pin_read("my_test_pin_data")
> packageVersion("pins")
[1] ‘1.0.1’
> 
juliasilge commented 1 year ago

Thanks for your patience on this! With the newer pins API, it's true that you can't set up a board object unless you can actually connect to it:

library(pins)
b <- board_rsconnect()
#> Connecting to RSC ??? at <https://colorado.rstudio.com/rsc>
#> Error in curl::curl_fetch_memory(url, handle = handle): Could not resolve host: colorado.rstudio.com

Created on 2022-11-04 with reprex v2.0.2

What still does work is a set of steps where you create the board object, then get disconnected from it and use the cache:

b %>% pin_read("julia.silge/very-good-numbers")
#> ✖ Failed to connect to RSC; using cached version
#>  [1]  1  2  3  4  5  6  7  8  9 10

I can see how that change could be frustrating, so let's keep this issue open a bit longer to collect other feedback from users on this issue. We could try to document what use_cache_on_failure does in a more clear way.

github-actions[bot] commented 1 year ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.