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

Don't automatically unbox vectors when making requests. #173

Merged
merged 3 commits into from
Sep 5, 2024

Conversation

plietar
Copy link
Member

@plietar plietar commented Sep 3, 2024

When upgrading to httr2, I rewrote some of the http client code and forgot to keep the auto_unbox = FALSE flag. This has caused uploads to outpack_server to break, as requests were now malformed.

The issue is that it is ambiguous whether list(x = 1) should be serialized as {"x": 1} or as {"x": [ 1 ]}, because R does not differentiate between scalar and vectors of length one.

By default, httr2 applies auto_unbox = TRUE, which leads to all length 1 vectors being unboxed into a JSON scalar. By explictly choosing setting that flag to FALSE, we may override this behaviour and keep all vectors as vectors by default. Scalars need to be marked as such with the scalar(x) function (defined as jsonlite::unbox(x)).

Frustratingly this did not get caught by our testsuite because we were always pushing more than one packet at a time. I've added a test for this particular case, pushing one packet and one file, to make sure regressions don't get introduced in the future.

When upgrading to httr2, I rewrote some of the http client code and
forgot to keep the `auto_unbox = FALSE` flag. This has caused uploads to
outpack_server to break, as requests were now malformed.

The issue is that it is ambiguous whether `list(x = 1)` should be
serialized as `{"x": 1}` or as `{"x": [ 1 ]}`, because R does not
differentiate between scalar and vectors of length one.

By default, httr2 applies `auto_unbox = TRUE`, which leads to all length
1 vectors being unboxed into a JSON scalar. By explictly choosing
setting that flag to `FALSE`, we may override this behaviour and keep
all vectors as vectors by default. Scalars need to be marked as such
with the `scalar(x)` function (defined as `jsonlite::unbox(x)`).

Frustratingly this did not get caught by our testsuite because we were
always pushing more than one packet at a time. I've added a test for
this particular case, pushing one packet and one file, to make sure
regressions don't get introduced in the future.
@plietar plietar requested review from M-Kusumgar and richfitz and removed request for M-Kusumgar September 4, 2024 10:32
@richfitz richfitz merged commit 08a2f60 into main Sep 5, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants