rstudio / pins-r

Pin, Discover and Share Resources
https://pins.rstudio.com
Other
301 stars 62 forks source link

Pinning object within unknown username to Posit Connect #789

Closed ryjohnson09 closed 9 months ago

ryjohnson09 commented 9 months ago

I believe this is related to the issue we experienced during our Posit Conf workshop. I'm using an eval instance of Posit Team and logged in as user posit. When I pin a model to Connect, things work great, and I can run the following code as many times as I want without error:

library(pins)

board <- board_connect()

cars_lm <- lm(mpg ~ ., data = mtcars)

pin_write(board = board, x = cars_lm, name = "posit/cars_lm")

However, if I then delete the pin on Connect and then change the username prefix to something like posit.fake, I can run the below code once, and it pins the model to Connect, which is unexpected since posit.fake is not a user on the Connect server:

library(pins)

board <- board_connect()

cars_lm <- lm(mpg ~ ., data = mtcars)

pin_write(board = board, x = cars_lm, name = "posit.fake/cars_lm")

If I try to run the same code a second time, I get this error:

! Can't find pin named 'cars_lm' with owner 'posit.fake'
Backtrace:
  1. pins::pin_write(board = board, x = cars_lm, name = "posit.fake/cars_lm")
  3. pins:::pin_store.pins_board_connect(...)
  8. pins:::rsc_content_find(board, name, warn = FALSE)
 11. pins:::rsc_content_find_live(board, name, version = NULL, warn = TRUE)

Somehow pins allows you to pin to Connect with a random username once, but not again. FWIW, I can't read the fake pin into an R session even if the access controls on Connect are open to anyone:

> pin_read(board, "posit.fake/cars_lm")
Error in `rsc_content_find_live()`:
! Can't find pin named 'cars_lm' with owner 'posit.fake'
Run `rlang::last_trace()` to see where the error occurred.
juliasilge commented 9 months ago

Wow 😮 not fun at all. I can reproduce this as well. See this pin that belongs to our coworker Julia Roberts:

Screenshot 2023-09-25 at 2 40 10 PM

The user and content caches are once again coming to make our lives miserable, as the local cache is not in sync with the situation on the Connect server. I think the problem is cropping up here:

https://github.com/rstudio/pins-r/blob/b853504053093f937f05b94d142c2cb3cc4f59a8/R/board_connect.R#L283-L292

When we go to rsc_content_find(), we never look up content live because in the cache, we look up by full name OR just the short name (no username):

https://github.com/rstudio/pins-r/blob/b853504053093f937f05b94d142c2cb3cc4f59a8/R/board_connect.R#L448

So then we can make our pin belonging to Julia Roberts by updating (rsc_content_update()) at the pin GUID that we just deleted.

This is not a problem in Python pins because in Python a) we don't keep any content or user caches but look everything up every time and b) usernames are required with Connect pins so we don't have to try to keep track of pin short names vs. full names.

I am wondering if we should again consider ripping out those caches altogether as we discussed related to #667. As a reminder, these are not the caches of the pin contents, but the local cache that pins tries to keep for the mapping from user names to user IDs and content names to GUIDs.

juliasilge commented 9 months ago

Fixed in #793

Now when you try to do something like:

pin_write(board = board, x = cars_lm, name = "posit.fake/cars_lm")

it will error because of the username not existing on the server.

github-actions[bot] commented 8 months 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.