[R] abandon_ship() looks up `call` with an inheriting get(), so its "no call" guard never fires
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu với r/R/dplyr-eval.R, đặc biệt là abandon_ship() quanh phần tra cứu lệnh gọi ở các dòng 252–255, và đọc các chú thích cùng bài kiểm thử gần đó về những biểu thức dplyr không được hỗ trợ. Tái hiện trường hợp wrapper trong issue, sau đó kiểm tra hành vi với cách tra cứu không kế thừa được đề xuất. Công việc hoàn tất khi wrapper phát sinh lỗi arrow_not_supported đã được tài liệu hóa, còn lời gọi trực tiếp vẫn giữ fallback hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug, including details regarding any error messages, version, and platform.
When an arrow dplyr verb is reached through a function that forwards ..., and the expression cannot be translated, the user gets
Error in `call$.data <- dplyr::collect(.data)`:
! object of type 'special' is not subsettable
instead of either the documented fallback to R or the arrow_not_supported error that abandon_ship() is written to raise in this situation.
Reproducer
library(arrow, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
tab <- arrow_table(k = c("a", "a", "b"), v = 1:3)
# Direct call: an expression Arrow cannot translate warns and falls back to R.
summarise(tab, out = dplyr::first(v))
#> Warning: In dplyr::first(v):
#> ℹ Expression not supported in Arrow
#> → Pulling data into R
#> # A tibble: 1 × 1
#> out
#> <int>
#> 1 1
# The same call through a wrapper that forwards `...` errors instead.
wrapper <- function(.data, ...) dplyr::summarise(.data, ...)
wrapper(tab, out = dplyr::first(v))
#> Warning: In dplyr::first(v):
#> ℹ Expression not supported in Arrow
#> → Pulling data into R
#> Error in `call$.data <- dplyr::collect(.data)`:
#> ! object of type 'special' is not subsettable
# The condition carries no Arrow class.
err <- tryCatch(
suppressWarnings(wrapper(tab, out = dplyr::first(v))),
error = identity
)
class(err)
#> [1] "notSubsettableError" "error" "condition"
# What abandon_ship()'s lookup returns when `call` was never bound in `env`:
env <- new.env()
found <- try(get("call", envir = env), silent = TRUE)
identical(found, base::call)
#> [1] TRUE
inherits(found, "try-error")
#> [1] FALSE
# With `inherits = FALSE` the existing guard would fire:
found <- try(get("call", envir = env, inherits = FALSE), silent = TRUE)
inherits(found, "try-error")
#> [1] TRUE
Created on 2026-11-26 with reprex v2.1.1
summarise() is only the example. mutate(), filter() and arrange() fail the same way through an equivalent wrapper, as do grouped queries and RecordBatch input. Only in-memory input is affected: a Dataset through the same wrapper already gets arrow_not_supported, and an expression Arrow can translate works through the wrapper as usual.
Cause
try_arrow_dplyr() captures the verb's call for later use (r/R/dplyr-eval.R#L233-L236):
try(
evalq(call <- match.call(), parent),
silent = !getOption("arrow.debug", FALSE)
)
When the verb's own call contains ..., this match.call() fails with ... used in a situation where it does not exist, so call is never bound in parent. The error is silenced unless options(arrow.debug = TRUE) is set. It does not need arrow to reproduce:
# try_arrow_dplyr()'s capture, reduced to base R.
capture <- function() {
parent <- parent.frame()
try(evalq(call <- match.call(), parent))
exists("call", envir = parent, inherits = FALSE)
}
verb <- function(.data, ...) capture()
wrapper <- function(.data, ...) verb(.data, ...)
verb(1, a = 1)
#> [1] TRUE
wrapper(1, a = 1)
#> Error in match.call() : ... used in a situation where it does not exist
#> [1] FALSE
Created on 2026-11-26 with reprex v2.1.1
abandon_ship() anticipates the missing binding (#L252-L255):
# If there's no call (see comment in try_arrow_dplyr), we can't eval with
# dplyr even if the data is in memory already
call <- try(get("call", envir = env), silent = TRUE)
if (query_on_dataset(.data) || inherits(call, "try-error")) {
but get() inherits by default, so the lookup walks out of env and returns base::call. That is not a try-error, the guard is skipped, and execution reaches call$.data <- dplyr::collect(.data), which tries to subset a special. Since R evaluates the right-hand side first, the whole input is collected before the error is raised.
Suggested fix
- call <- try(get("call", envir = env), silent = TRUE)
+ call <- try(get("call", envir = env, inherits = FALSE), silent = TRUE)
With only that line patched in a session, the wrapper gets the classed error and the direct call is unaffected:
library(arrow, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
# Patch the one lookup in abandon_ship() for this session.
ns <- asNamespace("arrow")
fn <- get("abandon_ship", ns)
src <- deparse(body(fn))
src <- sub(
'get("call", envir = env)',
'get("call", envir = env, inherits = FALSE)',
src,
fixed = TRUE
)
body(fn) <- parse(text = src)[[1]]
assignInNamespace("abandon_ship", fn, ns)
tab <- arrow_table(k = c("a", "a", "b"), v = 1:3)
wrapper <- function(.data, ...) dplyr::summarise(.data, ...)
# Through the wrapper: the classed error the source comments describe.
wrapper(tab, out = dplyr::first(v))
#> Error in `dplyr::first()`:
#> ! Expression not supported in Arrow
#> → Call collect() first to pull data into R.
err <- tryCatch(wrapper(tab, out = dplyr::first(v)), error = identity)
class(err)
#> [1] "arrow_not_supported" "rlang_error" "error"
#> [4] "condition"
# Direct call: the fallback is unchanged.
summarise(tab, out = dplyr::first(v))
#> Warning: In dplyr::first(v):
#> ℹ Expression not supported in Arrow
#> → Pulling data into R
#> # A tibble: 1 × 1
#> out
#> <int>
#> 1 1
Created on 2026-11-26 with reprex v2.1.1
This makes the guard do what it says. It does not make the fallback work through a wrapper: that would need the call captured some other way than match.call() under evalq(), which I have not attempted here.
History
The evalq(call <- match.call(), parent) capture and the inheriting get("call", envir = env) both date from #41576, which changed abandon_ship() to look the call up instead of receiving it as an argument. #43498 then wrapped the match.call() in try(), moved the get() into a try() of its own, and added the inherits(call, "try-error") test, to stop tidyquery's revdep failure seen in #43317. That PR notes that no reproducer could be written at the time; the wrapper above is one, and it shows the guard added there has not been firing.
I ran the code above on 26.0.1.1 only. From reading the source, the same lines are in every CRAN release from 17.0.0 (built from maint-17.0.0-r, which carries #43498) and on main. Up to 16.x, abandon_ship() received the call as an argument and this path did not exist.
Why it matters for calling code
Forwarding ... to a dplyr verb is the ordinary way to write a function or package on top of dplyr, so this is reachable without anything unusual. The resulting notSubsettableError cannot be told apart from any other misuse of $, whereas arrow_not_supported can be caught and names the offending expression.
Versions
- arrow 26.0.1.1 (CRAN)
- dplyr 1.2.1
- R 4.6.2
- macOS 27.2.1, aarch64
Drafted with an AI assistant (Claude). The three code blocks marked as reprex output are unedited output from the versions listed.
Component(s)
R
- Ngôn ngữ chính
- C++
- Star
- 17.3k
- Fork
- 4.5k
- Merge trung bình
- 3 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 90
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/arrow
-
[C++][Python][Docs] Some compute functions are missing from the docsCó thể đã có người làm @rajbhatt2406-collab đã nhận 1 ngày trước. Đang mởComponent: C++ Component: Documentation Component: Python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/arrow#55762 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Component: C++ Type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Component: C++ Type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Component: Continuous Integration Component: Developer Tools Type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
apache/arrow#55672 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Component: Python Type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
apache/arrow#55659 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Missing repro Platform: Android
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
software-mansion/react-native-reanimated#11554 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Niko1221/Strata#7211 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
sleepyviper1213/redis#52 ·