Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when deleting last version of a pin #837

Closed
MichalLauer opened this issue Aug 24, 2024 · 2 comments · Fixed by #838
Closed

Error when deleting last version of a pin #837

MichalLauer opened this issue Aug 24, 2024 · 2 comments · Fixed by #838

Comments

@MichalLauer
Copy link
Contributor

Hello,

Thanks for this great package!

I am uploading custom files to a local board. However, there is an error thrown whenever I

  1. create a board and a pin,
  2. upload a file using pin_upload(),
  3. remove that pin, and
  4. try to upload a new one.

Here is a custom reprex that replicates this issue:

library(pins)
#> Warning: package 'pins' was built under R version 4.3.3

# Prepare data
write.csv(mtcars, file = "mtcars.csv")

# Create temp board and first upload
board <- board_temp(versioned = TRUE)
pin_upload(board = board, paths = "mtcars.csv", name = "data")
#> Creating new version '20240824T203215Z-cd94d'

# Delete just created pin
latest_version <- pin_versions(board = board, name = "data")$version
pin_version_delete(board = board, name = "data", version = latest_version)

# Upload new data
pin_upload(board = board, paths = "mtcars.csv", name = "data")
#> Error in versions$version[[1]]: subscript out of bounds

I think the issue happens within the version_setup() on line 162:

pins-r/R/pin_versions.R

Lines 160 to 171 in 2edcccb

if (pin_exists(board, name)) {
versions <- pin_versions(board, name)
old_version <- versions$version[[1]]
n_versions <- nrow(versions)
if (old_version == new_version) {
cli::cli_abort(c(
"The new version {.val {new_version}} is the same as the most recent version.",
i = "Did you try to create a new version with the same timestamp as the last version?"
),
call = call)
}
} else {

because in that state, the board exists without any pins (and hence without any versions).

Could a simple fix be just a check in the if statement?

if (pin_exists(board, name) & length(versions) > 0) {
  ...
}

If so, happy to do a PR :) Thanks!

@MichalLauer MichalLauer changed the title Error when deleting a single pin Error when deleting last pin within a board Aug 24, 2024
@MichalLauer MichalLauer changed the title Error when deleting last pin within a board Error when deleting last version of a pin Aug 24, 2024
@juliasilge
Copy link
Member

Thanks so much for this report! I believe you have diagnosed the problem correctly, yes.

I don't think we can do if (pin_exists(board, name) & length(versions) > 0) because we can't do pin_versions() until we know the pin exists, but we can add an additional check inside the if statement, or maybe add a new little helper which could be called in the if statement after the currently existing part:

pin_version_exists <- function(board, name) {
  versions <- pin_versions(board, name)
  length(versions) > 0
}

We would welcome a PR with one of these fixes if you are interested! 🙌

Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants