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

Saving multiple queries on a single cassette #93

Closed
Rekyt opened this issue Feb 7, 2019 · 8 comments
Closed

Saving multiple queries on a single cassette #93

Rekyt opened this issue Feb 7, 2019 · 8 comments
Labels
Milestone

Comments

@Rekyt
Copy link

Rekyt commented Feb 7, 2019

cc @Bisaloo

We experience problems to record several request on a single vcr cassette.
The two first times always work when using record = new_episodes however for the third call we get the following error (see reprex below):

Error in z$response$status$status_code: $ operator is invalid for atomic vectors

Are we recording the cassette in the intended way?
Thanks!

Related issue

#67

Reprex

library("vcr")
#> Le chargement a nécessité le package : jsonlite
library("httr")

use_cassette("multiple_queries", {
  g404 = GET("https://httpbin.org//status/404")
  g500 = GET("https://httpbin.org/status/500")
  
  testthat::expect_equal(status_code(g404), 404)
  testthat::expect_equal(status_code(g500), 500)
}, record = "new_episodes")
#> CrulAdapter enabled!
#> HttrAdapter enabled!
#> net connect allowed
#> net connect disabled
#> encoding couldn't be detected; assuming UTF-8
#> ejecting cassette: multiple_queries
#> CrulAdapter disabled!
#> HttrAdapter disabled!
#> <vcr - Cassette> multiple_queries
#>   Record method: new_episodes
#>   Serialize with: yaml
#>   Persist with: FileSystem
#>   update_content_length_header: FALSE
#>   decode_compressed_response: 
#>   allow_playback_repeats: FALSE
#>   allow_unused_http_interactions: 
#>   exclusive: 
#>   preserve_exact_body_bytes: FALSE

use_cassette("multiple_queries", {
  g404 = GET("https://httpbin.org//status/404")
  g500 = GET("https://httpbin.org/status/500")
  
  testthat::expect_equal(status_code(g404), 404)
  testthat::expect_equal(status_code(g500), 500)
}, record = "new_episodes")
#> CrulAdapter enabled!
#> HttrAdapter enabled!
#> net connect allowed
#> net connect disabled
#> encoding couldn't be detected; assuming UTF-8
#> encoding couldn't be detected; assuming UTF-8
#> ejecting cassette: multiple_queries
#> CrulAdapter disabled!
#> HttrAdapter disabled!
#> <vcr - Cassette> multiple_queries
#>   Record method: new_episodes
#>   Serialize with: yaml
#>   Persist with: FileSystem
#>   update_content_length_header: FALSE
#>   decode_compressed_response: 
#>   allow_playback_repeats: FALSE
#>   allow_unused_http_interactions: 
#>   exclusive: 
#>   preserve_exact_body_bytes: FALSE

use_cassette("multiple_queries", {
  g404 = GET("https://httpbin.org//status/404")
  g500 = GET("https://httpbin.org/status/500")
  
  testthat::expect_equal(status_code(g404), 404)
  testthat::expect_equal(status_code(g500), 500)
}, record = "new_episodes")
#> CrulAdapter enabled!
#> HttrAdapter enabled!
#> Error in z$response$status$status_code: $ operator is invalid for atomic vectors

Created on 2019-02-07 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.1 (2018-07-02)
#>  os       Windows 8.1 x64             
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  French_France.1252          
#>  ctype    French_France.1252          
#>  tz       Europe/Paris                
#>  date     2019-02-07                  
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib
#>  assertthat    0.2.0      2017-04-11 [1]
#>  backports     1.1.3      2018-12-14 [1]
#>  base64enc     0.1-3      2015-07-28 [1]
#>  callr         3.1.1      2018-12-21 [1]
#>  cli           1.0.1      2018-09-25 [1]
#>  crayon        1.3.4      2017-09-16 [1]
#>  crul          0.7.0      2019-01-04 [1]
#>  curl          3.3        2019-01-10 [1]
#>  desc          1.2.0      2018-05-01 [1]
#>  devtools      2.0.1      2018-10-26 [1]
#>  digest        0.6.18     2018-10-10 [1]
#>  evaluate      0.12       2018-10-09 [1]
#>  fauxpas       0.2.0      2018-03-01 [1]
#>  fs            1.2.6      2018-08-23 [1]
#>  glue          1.3.0      2018-07-17 [1]
#>  highr         0.7        2018-06-09 [1]
#>  htmltools     0.3.6      2017-04-28 [1]
#>  httpcode      0.2.0      2016-11-14 [1]
#>  httr        * 1.4.0      2018-12-11 [1]
#>  jsonlite      1.6        2018-12-07 [1]
#>  knitr         1.21       2018-12-10 [1]
#>  lazyeval      0.2.1      2017-10-29 [1]
#>  magrittr      1.5        2014-11-22 [1]
#>  memoise       1.1.0      2017-04-21 [1]
#>  pkgbuild      1.0.2      2018-10-16 [1]
#>  pkgload       1.0.2      2018-10-29 [1]
#>  prettyunits   1.0.2      2015-07-13 [1]
#>  processx      3.2.1      2018-12-05 [1]
#>  ps            1.3.0      2018-12-21 [1]
#>  R6            2.3.0      2018-10-04 [1]
#>  Rcpp          1.0.0      2018-11-07 [1]
#>  remotes       2.0.2      2018-10-30 [1]
#>  rlang         0.3.1      2019-01-08 [1]
#>  rmarkdown     1.11       2018-12-08 [1]
#>  rprojroot     1.3-2      2018-01-03 [1]
#>  sessioninfo   1.1.1      2018-11-05 [1]
#>  stringi       1.2.4      2018-07-20 [1]
#>  stringr       1.3.1      2018-05-10 [1]
#>  testthat      2.0.1      2018-10-13 [1]
#>  triebeard     0.3.0      2016-08-04 [1]
#>  urltools      1.7.2      2019-02-04 [1]
#>  usethis       1.4.0      2018-08-14 [1]
#>  vcr         * 0.2.2.9311 2019-02-06 [1]
#>  webmockr      0.3.1.9111 2019-02-06 [1]
#>  withr         2.1.2.9000 2018-11-19 [1]
#>  xfun          0.4        2018-10-23 [1]
#>  yaml          2.2.0      2018-07-25 [1]
#>  source                            
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.2)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.2)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.2)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.2)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.2)                    
#>  CRAN (R 3.5.1)                    
#>  Github (ropensci/vcr@d25e537)     
#>  Github (ropensci/webmockr@e8fb9fe)
#>  Github (jimhester/withr@be57595)  
#>  CRAN (R 3.5.1)                    
#>  CRAN (R 3.5.1)                    
#> 
#> [1] C:/Users/grenie/Documents/R/R-3.5.1/library
@sckott sckott added this to the v0.2.4 milestone Feb 7, 2019
@sckott
Copy link
Collaborator

sckott commented Feb 7, 2019

thanks for this @Rekyt having a look

@sckott
Copy link
Collaborator

sckott commented Feb 7, 2019

problem is right here https://github.com/ropensci/vcr/blob/master/R/cassette_class.R#L418

on first use of use_cassette() it makes

http_interactions:
- request:
    method: get
    uri: https://httpbin.org//status/404
    body:
      encoding: ''
      string: ''
    headers:
      Accept: application/json, text/xml, application/xml, */*
  response:
    status:
      status_code: 404
      category: Client error
      reason: Not Found
      message: 'Client error: (404) Not Found'
    headers:
      connection: keep-alive
      server: gunicorn/19.9.0
      date: Thu, 07 Feb 2019 20:10:17 GMT
      content-type: text/html; charset=utf-8
      access-control-allow-origin: '*'
      access-control-allow-credentials: 'true'
      content-length: '0'
      via: 1.1 vegur
    body:
      encoding: UTF-8
      string: ''
  recorded_at: 2019-02-07 20:10:17 GMT
  recorded_with: vcr/0.2.2.9312, webmockr/0.3.1.9311

on 2nd it makes

http_interactions:
- request:
    method: get
    uri: https://httpbin.org//status/404
    body:
      encoding: ''
      string: ''
    headers:
      Accept: application/json, text/xml, application/xml, */*
  response:
    status: 404
    headers:
      connection: keep-alive
      server: gunicorn/19.9.0
      date: Thu, 07 Feb 2019 20:10:17 GMT
      content-type: text/html; charset=utf-8
      access-control-allow-origin: '*'
      access-control-allow-credentials: 'true'
      content-length: '0'
      via: 1.1 vegur
    body:
      encoding: UTF-8
      string: ''
  recorded_at: 2019-02-07 20:10:30 GMT
  recorded_with: vcr/0.2.2.9312, webmockr/0.3.1.9311

somehow replacing

  response:
    status:
      status_code: 404
      category: Client error
      reason: Not Found
      message: 'Client error: (404) Not Found'
...

with

  response:
    status: 404
...

In addition, it doesn't seem to happen if you only include 1 request, e.g,.

use_cassette("multiple_queries3", {
  g404 = GET("https://httpbin.org/status/404")
  testthat::expect_equal(status_code(g404), 404)
}, record = "new_episodes")

@sckott
Copy link
Collaborator

sckott commented Feb 7, 2019

Seems to be fine when using crul

@sckott
Copy link
Collaborator

sckott commented Feb 7, 2019

related issue #94 may be at fault here, not sure yet

sckott added a commit that referenced this issue Feb 8, 2019
bumped patch version
#93 multiple queries in a single use_cassette block now works fix #94
add tests specifically for httr
add tests for all the 4 record modes to make sure they work as expected
@sckott
Copy link
Collaborator

sckott commented Feb 8, 2019

@Rekyt i think it's fixed now. reinstall remotes::install_github("ropensci/vcr"), restart R, and try again

@sckott
Copy link
Collaborator

sckott commented Feb 9, 2019

webmockr is off to cran just now, if all goes well, can submit this to cran maybe monday or so

@Rekyt
Copy link
Author

Rekyt commented Feb 10, 2019

It works like a charm! Thank you so much @sckott ;)

@Rekyt Rekyt closed this as completed Feb 10, 2019
@sckott
Copy link
Collaborator

sckott commented Feb 10, 2019

great, glad it's working for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants