rstudio / pins-r

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

Rsconnect unable to write new pin #534

Closed joelgsponer closed 3 years ago

joelgsponer commented 3 years ago

Hi, Many thanks for your work I really like the ease of use of the pins package. Unfortunately, the recent update did introduce some headaches for me. I use the pins package to temporarily store some data on our company reconnect instance. Until now this worked perfectly. But now I am unable to write/create new pins. I am able to connect to the board without problems.

board <- pins::board_rsconnect(auth = "envvar")  #This works and I do see the present pins.
pins::pin_write(board, mtcars, "test")

but writing the pin results in a 404 error. Error in rsc_check_status(req) : Not Found (HTTP 404).

Digging into the code I think the issue might be here:

#' @export
pin_store.pins_board_rsconnect <- function(
   ...
{
  # [...]
  # Find/create content item
  content_guid <- tryCatch(
    {
      guid <- rsc_content_find(board, name, warn = FALSE)$guid
      rsc_content_update(board, guid, metadata, access_type = access_type)
      guid
    },
    pins_pin_missing = function(e) {
      rsc_content_create(board, name, metadata, access_type = access_type)$guid
    }
  )

As I understand it should try to find the pin and if not it expects the pins_pin_missing error. But this never happens as rsc_content_find throws a 404 error before.

rsc_content_find <- function(board, name, version = NULL, warn = TRUE) {
 #[...]
  # https://docs.rstudio.com/connect/api/#get-/v1/content
  json <- rsc_GET(board, "v1/content", list(name = name$name))
  if (length(json) == 0) {
    abort_pin_missing(name$name)
  }

So I never get to the pin creation part. Is this behavior on purpose? Should the response of the server upon GET be different (e.g. {})? Thanks Joël

joelgsponer commented 3 years ago

Ok, unfortunately after forking and changing the code to arrive at pin create I still get a 404. What is different in the API call from the previous version that makes it break now? I do not understand how I can connect to the board and see the pins but not GET or POST content. Many thanks Joël

joelgsponer commented 3 years ago

Inspecting our Instance I see: RStudio Connect API Reference 1.0.1 Build 1.8.4.2-2

dewoller commented 3 years ago

@joelgsponer , where did you find the instance information?

joelgsponer commented 3 years ago

@dewoller I found it in the documentation: image Under the API Reference section.

hadley commented 3 years ago

@dewoller it should also print the version when you run board_rsconnect()

sellorm commented 3 years ago

@joelgsponer If you're seeing the rsc_check_status/rsc_content_find 404 error, it might be worth checking to see if you have anything like a reverse proxy or Web Application Firewall in front of Connect that may be causing an issue.

We saw something similar in #539, which turned out to be a WAF rule blocking certain types of API request.

hadley commented 3 years ago

This doesn't seem to be a widespread problem, and I can't reproduce so I'm going to close.

j-andrews7 commented 2 years ago

We are having this same issue - cannot read old pins nor write new ones with pins 1.0.0 or dev version with RSC 1.8.4.2-2. I am presuming this is the same issue as #539, but I don't have access to the RSC server to determine what's wrong.

Just adding that there will likely be more reports of this over time as more people update things.

hadley commented 2 years ago

@j-andrews7 I'd recommend upgrading to pins 1.0.1 (released yesterday) and then if you have another problem please file a new issue with reprex/traceback.

saadaslam commented 2 years ago

I did some research here, and I think it depends on the setup of your RStudio Connect instance as I'm having the same issue. I think there may be something with the instance where the API isn't enabled. The URL that httr queries is effectively something like https://my.rsc.com/__api__/v1/content?name=my-data. Typing that into my browser, I get a 404 error.

sellorm commented 2 years ago

For anybody finding this thread later, one of the Connect APIs that pins uses, /v1/content, was only introduced in Connect 1.8.6. Prior to that, it was an experimental API and so was not stable or available on the same path.

Anybody else encountering the same issue should consider upgrading their Connect instance.

github-actions[bot] commented 2 years 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.