Skip to content

feat: Keep the driver in each connection and the connection in each result - #794

Open
krlmlr wants to merge 18 commits into
mainfrom
claude/dbconnect-args-slot
Open

krlmlr wants to merge 18 commits into
mainfrom
claude/dbconnect-args-slot

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Adds a .dbi slot to the virtual base classes DBIConnection, DBIResult, and DBIResultArrow, and lets DBI's generics fill it after dispatch, for every backend and without changes to backends. First use case, as decided by Kirill: keep the driver object in each connection, and the connection object in each result and Arrow result. The capture of DBI-level arguments to dbConnect() moved to the stacked #800, as Kirill asked.

Changes

  • DBIConnection, DBIResult, and DBIResultArrow get a slot .dbi of class list, with prototype list(); DBIResultArrowDefault inherits it. DBIObject, and with it DBIDriver and DBIConnector, does not get it.
  • The dbConnect() generic stores the driver; dbSendQuery(), dbSendStatement(), and dbSendQueryArrow() store conn. In the default dbSendQueryArrow() method, both the wrapper and the wrapped result get the connection.
  • Through a DBIConnector, the connection keeps the connector's inner driver, so the connector's arguments, possibly with credentials, are not copied into connections and results. A clone made with dbConnect(con) keeps the original connection's driver, not the original connection. Nested connectors and connections are unwrapped, up to a small depth.
  • Everything is written with attr(), never @, in a helper that never fails or changes the return value (R/dbi-state.R). Internal readers dbi_driver(), dbi_connection(), and dbi_setting() return NULL or the default when absent.
  • The class and generic docs say what DBI stores in .dbi, that code reads it with attr(x, ".dbi", exact = TRUE), and that backends must not write to it.
  • No change to the declared R version.

Compatibility

  • Binary RSQLite 3.53.3 and duckdb 2.0.1, built against DBI 1.3.0 and lacking the slot in their cached class definitions, work with this DBI: dbConnect(), dbSendQuery(), dbSendQueryArrow(), dbFetch(), dbClearResult(), validObject(), and the attributes are set.
  • Garbage collection and finalizers behave as with DBI 1.3.0 for RSQLite and duckdb.
  • Every connection and result now carries .dbi, so identical() comparisons and str() output change. Serialized results grow; a duckdb result doubles (10000 → 20431 bytes). The bookkeeping costs about 7 µs per call.
  • devtools::test() on R 4.5.3: 0 failures.

Status

https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje


Generated by Claude Code

The `DBIConnection` class gains a `.dbi_state` slot that holds an environment,
with `emptyenv()` as prototype so that no two objects share mutable state.
After the method returns, the `dbConnect()` generic records the arguments passed in `...`
in a fresh environment in that slot.
`dbGetConnectArgs()` gains a `DBIConnection` method that returns them,
evaluating function arguments as for connectors.
Through a `DBIConnector`, the connector's arguments are recorded unevaluated.

The slot is read and written with `attr()`,
so that backends installed against an older DBI keep working without reinstalling,
as do objects deserialized from an older DBI.
Recording never fails `dbConnect()`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: Name and scope of the new slot on DBIConnection?

The prototype adds a slot .dbi_state holding an environment, with emptyenv() as the prototype so that objects created with new() share no mutable state. Today it holds only conn_args; an environment lets DBI add further per-connection settings later (such as the lazy Arrow switch from #783) without another class change.

  • .dbi_state, a general per-connection state environment (recommended): one slot for all future DBI-level settings.

  • .conn_args, holding only the arguments: narrower and self-describing, but the next setting needs another slot.

  • .dbi: shorter, same scope as .dbi_state.

  • A list in a slot named .dbi, decided by Kirill, relayed from the session chat: "use a list named .dbi, only capture arguments that DBI needs. Don't add a new generic, document looking up the .dbi slot instead."

Kirill decides. If nobody decides, the slot stays .dbi_state.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: Store the driver object along with the arguments?

set_connect_args() stores list(...) only, not drv, mirroring what DBIConnector keeps in .conn_args.

  • Arguments only (recommended): mirrors DBIConnector, keeps the stored state small, and avoids keeping driver objects alive.

  • Also store drv: makes the connection fully reproducible (do.call(dbConnect, c(drv, args))), at the cost of holding a reference to the driver, which for some backends holds external resources.

  • Neither the driver nor backend arguments: only the arguments DBI itself needs are captured, decided by Kirill, relayed from the session chat: "use a list named .dbi, only capture arguments that DBI needs. Don't add a new generic, document looking up the .dbi slot instead."

  • Superseded by a later decision: store the driver object in each connection, and the connection object in each result and Arrow result, decided by Kirill, relayed from the session chat: "Bump to R 4.1 and use ...names() and ...elt(). First use case: capture driver object in each connection and connection object in each result and Arrow result. Make this the goal of feat: Keep the driver in each connection and the connection in each result #794."

Kirill decides. If nobody decides, only the arguments are stored.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: How to capture arguments that the backend's method did not evaluate?

The generic calls list(...) after the method has returned. Arguments the method already used are not evaluated again, but arguments it ignored are forced at that point, and if one of them errors, nothing is stored (dbConnect() itself still succeeds). A deliberately lazy argument, such as an interactive password prompt the backend skipped, would run once more here.

  • Force each argument separately, store the ones that evaluate, and skip the ones that error (recommended): partial information instead of none; side effects of ignored arguments remain.

  • Keep list(...) as is: simplest; all-or-nothing.

  • Store unevaluated expressions (substitute()/match.call()) and evaluate only in dbGetConnectArgs(eval = TRUE): never forces anything, but the stored expressions depend on the caller's environment, which then stays alive.

  • Only the arguments DBI itself needs are captured, so backend arguments are never forced; decided by Kirill, relayed from the session chat: "use a list named .dbi, only capture arguments that DBI needs. Don't add a new generic, document looking up the .dbi slot instead."

Kirill decides. If nobody decides, list(...) stays.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: Should passwords and other secrets passed to dbConnect() be retained?

With this PR, every argument passed to dbConnect() is kept in the connection, including passwords and tokens given as plain values. show(), print() and str() do not reveal them, but they are part of the bytes of a serialized connection (saveRDS(), or a workspace saved with it), and anyone holding the object can read them with dbGetConnectArgs(). On main, such values are not retained by DBI (backends may still keep their own copies). DBIConnector already has the same property for its stored arguments and documents passing secrets as functions.

  • Store only DBI-level settings that DBI itself reads, not arbitrary backend arguments (recommended): no new copies of secrets; the stated use case (per-connection settings such as lazy Arrow fetching) still works, but dbGetConnectArgs() on a connection then does not return everything.

  • Store everything, and document the retention and the function form for secrets, as for DBIConnector: full information for reconnecting or describing a connection; secrets given as plain values are kept.

  • Store everything except arguments whose names look like secrets (password, pwd, token, key, ...): partial protection based on a name list that can never be complete.

  • Store only the arguments DBI itself needs (the first option), decided by Kirill, relayed from the session chat: "use a list named .dbi, only capture arguments that DBI needs. Don't add a new generic, document looking up the .dbi slot instead."

Kirill decides. If nobody decides, everything is stored and documented, as in the prototype.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: In nested dbConnect() calls, which call's arguments are kept?

Reposted for the .dbi design: #794 (comment)

A dbConnect() method can call dbConnect() again, as dbConnect(<DBIConnector>) does. In the prototype, the outermost call wins: for a connector, the stored arguments are the connector's, unevaluated, so a password given as a function stays a function.

  • Outermost call wins (recommended): what the user typed is what is stored, and connector secrets stay functions.
  • Innermost call wins: what the backend actually received, with connector functions already evaluated.

Kirill decides. If nobody decides, the outermost call wins.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: How do DBI-level settings reach the connection without breaking strict backends?

Reposted for the .dbi design: #794 (comment)

The motivating use case is a DBI-level per-connection setting such as dbConnect(drv, ..., lazy_arrow = TRUE) (#783). With the current generic, such an argument is passed on to the backend's method like any other, and a backend that rejects unknown arguments would error.

  • The generic strips arguments with a reserved prefix (e.g. dbi.lazy_arrow) before dispatch and stores them separately (recommended): works with every backend unchanged; DBI owns a small, documented namespace of argument names.
  • Pass everything through, and expect backends to accept and ignore unknown arguments: simplest, but fails on strict backends.
  • No DBI-level arguments; a separate setter such as dbSetOption(con, ...) after connecting: no change to dbConnect() dispatch, but not a dbConnect() argument as asked.

Kirill decides. If nobody decides, nothing is stripped and no DBI-level argument is defined yet.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Clean review, round 1 (at b57cd87)

Reviewed by an agent without context from the work, briefed with S4 class caching across old and new DBI, serialization, secrets, argument forcing, robustness, downstream impact, and tests.

High

  1. Passwords end up in serialized connections. set_connect_args() stores list(...) on every connection. On main, RSQLite and duckdb connections hold no password; now saveRDS(), serialize(), a saved workspace (.RData), exports to future/callr workers, and knitr or targets caches write it in plain text. serialize() of an RSQLite connection contains the password, and an RDS file read in a fresh session without DBI still exposes it through the attribute. str(), dput(), show() and dbGetInfo() do not leak it. Documented in the help page, not in NEWS. → secrets question

Medium

  1. Arguments the backend ignored are now evaluated after it connects: dbConnect(drv, password = side()) runs side() zero times on main and once with this PR (RSQLite, duckdb, minimal backend); a slow or prompting argument now delays or prompts after connecting; warnings surface late. Errors are swallowed correctly. → forcing question
  2. Downstream tests that compare or snapshot connections break: a mock whose dbConnect() method returns a prebuilt object is no longer identical() to it, two connections with the same arguments are no longer identical(), and for backends rebuilt against this DBI str(con) shows an environment address that changes on every run (expect_snapshot(str(con))). Mocking packages are the likely casualties (not tested: not installed). → question below

Low

  1. The state environment is reused and modified in place (lines 37–42): a wrapper created with new("Wrapper", inner_con) shares the inner connection's environment, so the outer dbConnect() overwrites the inner arguments. Fixed in f88d6b7: every connection gets a fresh environment, with a regression test.
  2. The "no slot" test helper simulates an old-DBI class by removing the attribute rather than using a real one; the real case was verified separately (below).
  3. A backend subclass that defines its own .dbi_state slot with another type now fails at install time; unlikely to exist.

Checked and correct

  • Old and new DBI in all four combinations (backend built against old or new DBI, run with old or new DBI), with external-pointer classes, initialize() calling validObject(), prototype(), and setRefClass(): dbConnect(), validObject(), new(class, con) work, isVirtualClass("DBIConnection") stays TRUE, and serialized objects read back under every combination. RSQLite 3.53.3 and duckdb 2.0.1 binaries built against DBI 1.3.0 run queries with this DBI.
  • Nested calls (outermost wins), non-DBIConnection return values untouched, erroring arguments do not fail dbConnect(), connector eval = FALSE semantics consistent, parent.frame() in methods unchanged.

Tests: devtools::test() FAIL 0, WARN 0, SKIP 59, PASS 9756; each new test_that() passes alone after load_all(); man pages change only as intended.

Not checked: pool, odbc, RPostgres, mocking packages, otel, the RStudio and Positron connection panes, a reverse-dependency run, R CMD check.

Note: the recommended options of the secrets and DBI-level settings questions together remove the High and both Medium findings: if DBI stores only its own reserved-prefix settings, backend arguments (and their secrets) are neither stored nor forced, and a connection made without such settings gets no state at all, so it stays identical() to what the backend returned.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: Accept that connections no longer compare identical() and that str() output changes?

The clean review (Medium 2) found that every connection now carries a fresh state environment. A mock whose dbConnect() method returns a prebuilt object is no longer identical() to it, two connections made with the same arguments are no longer identical(), and for backends rebuilt against this DBI, str(con) prints an environment address that changes on every run, which breaks expect_snapshot(str(con)) in downstream tests.

  • Attach state only when there is something DBI needs, i.e. DBI-level settings as in the recommended option (recommended): connections made without such settings are unchanged, so existing comparisons and snapshots keep working.

  • Accept the change for all connections and announce it in NEWS: full argument capture everywhere, at the cost of breaking such tests downstream, to be checked in a reverse-dependency run.

  • Store a plain list instead of an environment: str() becomes deterministic, but the arguments then show up in str() output, and connections still differ from mocks.

  • A list in .dbi holding only the arguments DBI needs, so connections made without them are unchanged and str() is deterministic; decided by Kirill, relayed from the session chat: "use a list named .dbi, only capture arguments that DBI needs. Don't add a new generic, document looking up the .dbi slot instead."

  • Note: with the driver now stored in every connection (and the connection in every result), every connection and result carries a .dbi value, so the identical() and str() changes described above apply again, decided by Kirill, relayed from the session chat: "Bump to R 4.1 and use ...names() and ...elt(). First use case: capture driver object in each connection and connection object in each result and Arrow result. Make this the goal of feat: Keep the driver in each connection and the connection in each result #794."

Kirill decides. If nobody decides, every connection gets the state as in the prototype.


Generated by Claude Code

A wrapper created with `new("Wrapper", inner_con)` copies the attribute,
so it shared the state environment of the inner connection.
The outer `dbConnect()` then overwrote the inner connection's stored arguments.
`set_connect_args()` now always creates a fresh environment
and copies over any other entries of the existing state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS
This follows Kirill's decision on #794.
The `.dbi_state` environment slot becomes a `.dbi` slot of class `list`,
and the `dbConnect()` generic keeps only the arguments DBI itself needs.
Their names live in `dbi_connect_arg_names()`, empty for now,
where future DBI-level settings are added.
Other arguments are neither evaluated nor kept,
and a connection made without DBI-level arguments is left untouched.

The `dbGetConnectArgs()` method for `DBIConnection` is gone,
and the connector code is back to what `main` has.
The docs say instead to read the slot with `attr(con, ".dbi", exact = TRUE)`,
because objects from backends installed against an older DBI lack it.
DBI's own methods read it with the internal `dbi_setting()`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: How do DBI-level arguments get past backends, and how are they named?

Moved to the stacked PR #800 with the DBI-level arguments: #800 (comment)

Reposted for the .dbi design (6dd0466). The generic still passes every argument on to the backend's method, and only afterwards captures the arguments named in dbi_connect_arg_names(), which is empty for now. Once a DBI-level argument such as lazy Arrow fetching (#783) is added, a backend whose method rejects unknown arguments errors on it, and a backend with an argument of the same name would receive DBI's value.

  • Reserve a prefix (e.g. dbi_lazy_arrow or dbi.lazy_arrow) and have the generic strip arguments with it before dispatch (recommended): works with every backend unchanged, no clash with backend argument names, and the list of names stays DBI's own.
  • Keep passing everything through and use plain names: simplest, but fails on strict backends and can clash with a backend's own argument.
  • Use a prefix, but keep passing the arguments through: no clash, but strict backends still fail.

Kirill decides. If nobody decides, arguments are passed through and no name is reserved; this only matters once the first DBI-level argument is added.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: In nested dbConnect() calls, which call's DBI-level arguments are kept?

Moved to the stacked PR #800 with the DBI-level arguments: #800 (comment)

Reposted for the .dbi design (6dd0466). A dbConnect() method can call dbConnect() again, as dbConnect(<DBIConnector>) does. The inner call stores its DBI-level arguments first; the outer call then merges its own over them, so on a name passed at both levels the outermost call wins, and names passed at only one level are all kept. A test covers the connector path.

  • Merge, outermost wins on conflicts, as now (recommended): what the user typed takes precedence, and settings from a connector or wrapper are not lost.
  • Innermost call wins on conflicts: what the inner call received takes precedence.
  • Outermost call replaces everything: simplest to explain, but drops settings the inner call added.

Kirill decides. If nobody decides, the merge with outermost wins stays.


Generated by Claude Code

@krlmlr krlmlr changed the title feat: Store the arguments to dbConnect() in the connection object feat: Keep the arguments DBI needs from dbConnect() in a .dbi slot Nov 29, 2026

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Clean review, round 2 (6dd0466 and the merge 68c1f92)

Scope: the .dbi rework and the merge of main; the rest of the PR was context. No correctness bug found in the capture logic, the S4 behavior across DBI versions, or the merge.

Medium

  1. A backend subclass that already defines its own .dbi slot of another type can no longer be installed against this DBI: setClass("MiniOther", contains = "DBIConnection", slots = c(.dbi = "character")) fails at lazy load with "Definition of slot '.dbi' ... conflicts with definition, inherited from class "DBIConnection"". No backend with such a slot is known; CRAN was not searched. → question below

Low

  1. A DBI-level argument whose evaluation errors is dropped silently, so a typo falls back to the default without a message (intended by "never fail dbConnect()", not documented). → question below
  2. Duplicated names (dbi_x = 1, dbi_x = 2) keep the last value, while the backend's method receives both. Accepted.
  3. The class docs called the slot "a named list", but the prototype is an empty unnamed list. Fixed in a8b440e.

Checked and correct

  • Capture: unnamed and missing arguments, an empty dbi_x =, forwarding through two wrapper frames (evaluated in the caller's frame), do.call() with values, ..1 forwarding, NULL values, drv passed by name, the DBIConnector merge. A non-DBI argument with a side-effect counter is never forced; a DBI argument is evaluated once even if the method forces it too.
  • Without DBI arguments the connection is identical() to what the backend returned.
  • RSQLite 3.53.3 and duckdb 2.0.1 binaries built against DBI 1.3.0 work with this DBI: queries, validObject(complete = TRUE), saveRDS() round trip; the attribute is NULL and [email protected] errors, as documented. A minimal backend built against this DBI works with DBI 1.3.0, including initialize() with validity, setRefClass(), and external-pointer classes; str() shows ..@ .dbi: list() deterministically.
  • The merge: the DBItest 1.9.0 spec changes touch only Arrow and dbFetch() text, no semantic conflict; man pages in sync.
  • Tests: every new test_that() passes alone after load_all(); mocks are undone.

Results: devtools::test() with DBItest 1.9.0.9000: FAIL 0, SKIP 65, PASS 9759. R CMD check --no-manual --ignore-vignettes: one NOTE about a hidden .git from building in a worktree; codoc and Rd checks OK.

Not checked: CRAN and reverse dependencies for existing .dbi slots or attributes, the otel path, a full check with manual and vignettes.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Question: Accept that a backend with its own .dbi slot can no longer be installed?

The new slot is inherited by every connection class. A backend that already defines a slot named .dbi with a different type fails to install against this DBI ("conflicts with definition, inherited from class "DBIConnection""). No such backend is known, but neither CRAN nor the reverse dependencies were searched.

  • Keep .dbi and check the reverse dependencies before release (recommended): the name you chose stays; a conflict, if any, shows up in the revdep run and can be handled with the backend's maintainer.
  • Rename to something less likely to clash, e.g. .DBI or .dbi_args: lowers the already small risk, at the cost of a less obvious name.

Kirill decides. If nobody decides, .dbi stays and the check happens in the next reverse-dependency run.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Warn when a DBI-level argument fails to evaluate?

Moved to the stacked PR #800 with the DBI-level arguments: #800 (comment)

In set_dbi_args(), a DBI-level argument whose evaluation errors is dropped without a message, so a typo such as dbConnect(drv, dbi_x = typo_var) silently falls back to the default. This keeps dbConnect() from ever failing because of DBI's own bookkeeping. No DBI-level argument exists yet, so this matters only once the first one is added.

  • Emit a warning naming the argument and the error, and keep connecting (recommended): the typo becomes visible, and dbConnect() still succeeds.
  • Stay silent, and document it: no noise, but mistakes go unnoticed.
  • Let the error propagate: strictest, but dbConnect() then fails after the backend has already connected, leaving a connection nobody can close.

Kirill decides. If nobody decides, the argument is dropped silently.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by the current copy.

  • R/03-DBIConnection.R#L31-L36: a backend subclass that defines its own .dbi slot of another type fails to install against this DBI (question). Relevance low (no such backend known, revdeps not searched); reviewer confidence high.
  • R/dbi-args.R#L35-L41: a DBI-level argument that fails to evaluate is dropped silently (question). Relevance low until the first DBI-level argument exists; reviewer confidence high.
  • R/dbi-args.R#L26-L53: duplicated DBI-level argument names keep the last value, while the backend's method receives both. Relevance very low (a caller error); reviewer confidence high.

Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Question: Document attr(con, ".dbi") or [email protected] for reading the slot?

The docs of DBIConnection and dbConnect() tell code to read the slot with attr(con, ".dbi", exact = TRUE). S4 caches each class definition in the package that defines it, at install time, so a backend installed against a DBI without the slot creates connection objects without it: on those, [email protected] fails with "no slot of name '.dbi'", while attr() reads the same value and returns NULL when it is absent. Both review rounds saw this with the RSQLite 3.53.3 and duckdb 2.0.1 binaries; connections saved with an older DBI behave the same. DBI's own reader dbi_setting() uses attr() either way.

  • Document attr(con, ".dbi", exact = TRUE) only (recommended): works on every installed backend and on old saved objects, with no requirement to rebuild.
  • Document [email protected], and say that it needs a backend installed against this DBI or later: idiomatic S4, but fails for users with older backend binaries, possibly for years.
  • Document both: @ for code that controls its installation, attr() otherwise.

Kirill decides. If nobody decides, the docs keep attr().


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by the current copy.

  • R/03-DBIConnection.R#L31-L36: a backend subclass that defines its own .dbi slot of another type fails to install against this DBI (question). Relevance low (no such backend known, revdeps not searched); reviewer confidence high.
  • R/dbi-args.R#L35-L41: a DBI-level argument that fails to evaluate is dropped silently (question). Relevance low until the first DBI-level argument exists; reviewer confidence high.
  • R/dbi-args.R#L26-L53: duplicated DBI-level argument names keep the last value, while the backend's method receives both. Relevance very low (a caller error); reviewer confidence high.

Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: Formals after ... are not viable; read ... with ...names() and ...elt() instead?

Kirill asked (relayed) whether the generic can declare the arguments it captures, without the current scan of .... An experiment with a scratch DBI whose generic is function(drv, ..., dbi_test = NULL), on R 4.5.3, 4.2.3 (oldrel-4) and 4.1.3 (oldrel-5), says no:

  • Backends already installed against the current generic keep working (RSQLite, duckdb, and a minimal backend with function(drv, ...), function(drv, dbname, ...), extra named arguments, callNextMethod(), and a recursive call): dispatch works, dbi_test is captured and never reaches the method's ..., no load-time warnings.
  • But building a backend against the new generic fails: R CMD INSTALL errors with "arguments ('dbi_test') after '...' in the generic must appear in the method, in the same place at the end of the argument list" (methods::rematchDefinition()), for every method that has its own arguments, which includes RSQLite's and duckdb's. A backend that adds the argument installs, but gets a codoc WARNING, and once built it fails every dbConnect() call under the current DBI ("could not find symbol "dbi_test" in environment of the generic function").
  • So each new DBI-level argument would force every backend to change its method formals and docs and to require that DBI version. Nothing was committed.

What remains is how to read ... in the generic. The branch uses names(substitute(list(...))) and eval(as.name("..i")) because DESCRIPTION declares R (>= 3.0.0); base R has had ...elt() since R 3.5.0 and ...names() since R 4.1.0, which do the same without the tricks. On the branch as it stands, the new tests pass on R 4.5.3, 4.2.3 and 4.1.3 (24 of 24), and so does the rest of the suite there (139 passed, 1 skipped for lack of DBItest).

  • Bump Depends to R (>= 4.1.0) and use ...names() and ...elt() (recommended): readable base R, R 4.1 is oldrel-5 and already tested here.

  • Keep R (>= 3.0.0) and the current code: no change to the declared R requirement.

  • Use ...elt() (R 3.5) with names(match.call(expand.dots = FALSE)$...) for the names, and bump to R (>= 3.5.0): smaller bump, still one idiom less readable.

  • Bump to R (>= 4.1.0) and use ...names() and ...elt() (the first option), decided by Kirill, relayed from the session chat: "Bump to R 4.1 and use ...names() and ...elt(). First use case: capture driver object in each connection and connection object in each result and Arrow result. Make this the goal of feat: Keep the driver in each connection and the connection in each result #794."

Kirill decides. If nobody decides, the current code stays.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by the current copy.

  • R/03-DBIConnection.R#L31-L36: a backend subclass that defines its own .dbi slot of another type fails to install against this DBI (question). Relevance low (no such backend known, revdeps not searched); reviewer confidence high.
  • R/dbi-args.R#L35-L41: a DBI-level argument that fails to evaluate is dropped silently (question). Relevance low until the first DBI-level argument exists; reviewer confidence high.
  • R/dbi-args.R#L26-L53: duplicated DBI-level argument names keep the last value, while the backend's method receives both. Relevance very low (a caller error); reviewer confidence high.

Generated by Claude Code

`...names()` reads the names of the arguments without forcing them,
and `...elt()` forces only the one asked for,
replacing `substitute()` and the `..i` symbols.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: Accept the extra copy of the connection in serialized results?

The result generics now store the connection in every result. Serialized sizes, before and after (bytes): RSQLite connection 1051 → 1328, RSQLite result 1215 → 1922, duckdb connection 9070 → 9887, duckdb result 10000 → 20431. The duckdb result doubles because its own slot already holds the connection and serialization writes a second copy.

  • Accept it (recommended): a result is rarely serialized, and a live connection cannot be restored from a serialized one anyway; the cost is bytes, not behavior.
  • Skip storing the connection when the backend's result already holds it in a slot: smaller, but DBI then has to inspect backend slots, which couples it to backend internals.

Kirill decides. If nobody decides, the copy is accepted.


Generated by Claude Code

@krlmlr krlmlr changed the title feat: Keep the arguments DBI needs from dbConnect() in a .dbi slot feat: Keep the driver in each connection and the connection in each result Nov 29, 2026

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Clean review of "keep the driver in each connection and the connection in each result" (a8b440e..2bf79a5)

Scope: the commits for this change, without the merge of main; the rest of the PR was context. No correctness bug in return values, dispatch, or the never-fail path.

High

  1. Cloning keeps the parent connection alive: after c2 <- dbConnect(c1); rm(c1); gc(), main finalizes c1 with RSQLite's "call dbDisconnect()" warning; with this change c1 lives on in c2's stored drv, with its SQLite handle open and no warning. Repeated cloning chains up: 50 clones serialize to 25616 bytes against 628 on main, and dbi_driver() can return an already disconnected connection. → Being fixed by storing the original connection's driver instead, as recommended in the cloning question.

Medium

  1. A DBIConnector stored as drv puts its literal credentials into every connection and every result: serialize() of a result contains the password; saveRDS() and future/callr exports now carry it. → connector question
  2. Per-call overhead: 20000 × dbExecute() on RSQLite :memory: takes 4.49 s against 3.66 s on main (+22%); a bare dbSendQuery() dispatch costs about 15 µs more; on the dbSendStatement() → dbSendQuery() default path the bookkeeping runs twice. → Being fixed.
  3. Serialized results grow by a copy of the connection (an old duckdb 2.0.1 result: 14003 → 24434 bytes), and DBIResultArrowDefault stores it twice, in the wrapper and in the wrapped result. → serialization question

Low

  1. The DBIResult and DBIResultArrow docs say attr() returns NULL for objects without the slot, but the generics add the attribute to those objects too. → Being fixed.
  2. Downstream: str()/dput() snapshots now show the nested driver or connection; identical() between a result a backend stashed internally and the copy the user receives fails, because attr<- copies the object; dbSendQuery(), dbSendStatement() and dbSendQueryArrow() are now nonstandard generics. A GitHub code search of CRAN found no package with a .dbi slot and no slotNames(con) checks.
  3. dbi_driver(), dbi_connection() and dbi_setting() have no callers yet, so the retention buys nothing today.

Checked and correct: return values and visibility unchanged when the bookkeeping fails; dbBind() and params, dbGetQuery(), dbExecute(); old-installed RSQLite 3.53.3 and duckdb 2.0.1 objects get the attribute and pass validObject(); pool (dbPool(), checkout and return) and dbplyr (tbl(), collect(), self-join) work; no reference cycle (RSQLite and duckdb results already hold their connection); ...names() on R 4.1.3; the R 4.1 bump is consistent; tests stand alone.

Tests: R 4.5.3: FAIL 0, WARN 0, SKIP 60, PASS 9832. R 4.1.3: no failures.

Not checked: reverse dependencies; backends whose results don't already hold their connection (odbc, RPostgres, bigrquery not installed); otel.


Generated by Claude Code

`dbConnect(con)` kept `con` as the driver of the clone.
The clone then kept the original connection alive, and clones of clones formed a chain.
The clone now keeps the driver of the original connection, or none if that connection has none.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS
`set_dbi_state()` runs once per call to `dbConnect()`, `dbSendQuery()`, `dbSendStatement()` and `dbSendQueryArrow()`.
It now tests the class with one `inherits()` instead of up to three calls to `is()`.
It returns early if the values are stored already, as on the default path from `dbSendStatement()` to `dbSendQuery()`.
Only the write runs inside `tryCatch()`, so the function still never fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS
The generics store the attribute even in objects whose class lacks the slot,
so `attr()` returns `NULL` only when DBI has stored nothing.
The documentation of `dbConnect()` also says which driver a clone keeps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Question: Keep the tryCatch() guard around DBI's bookkeeping, at about 4 µs per call?

After 8cab515, set_dbi_state() wraps only the write in tryCatch(), so DBI's bookkeeping can never fail a dbConnect() or dbSendQuery() call or change its return value. The review measured +22% for 20000 × dbExecute() on RSQLite :memory: before the fix; afterwards the remaining dispatch overhead of a bare dbSendQuery() is about 7 µs (19–20 µs against 11–13 µs on main, noisy machine), of which roughly 4 µs is the tryCatch(). The guarded write is an attr<- on an S4 object, which is not expected to fail.

  • Keep the guard (recommended): a bug or an unusual backend object can never break a query; 4 µs is small next to a database round trip.
  • Drop the guard: about 4 µs less per call, at the risk that an unexpected object makes dbConnect() or dbSendQuery() fail after the backend has already done its work.

Kirill decides. If nobody decides, the guard stays.


Generated by Claude Code

A classed list would dispatch on `[` in the check for stored values,
which can fail outside the guard, so the value is unclassed first.
Also say what a clone keeps when the original connection keeps no driver.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Clean review of the fixes (2bf79a5..04202a1)

Scope: the three fix commits for the previous round. No High or Medium findings, so the review stops here.

Low, both fixed in 5942375:

  1. The check for already stored values indexed the .dbi value outside the guard, so a classed value (e.g. a data frame written by a backend that breaks the "must not write" rule) made dbConnect() or dbSendQuery() fail with "undefined columns selected". The value is now unclassed first, with a test.
  2. The dbConnect() docs did not say what a clone keeps when the original connection keeps no driver: what the backend's method stores, e.g. RSQLite's clone method calls dbConnect(SQLite(), ...) and so stores an SQLiteDriver. Reworded.

Checked and correct

  • Clones: RSQLite 3.53.3 binary without the slot (clone and clone of clone keep SQLiteDriver), DBIConnector, a non-S4 driver, an S3-classed "DBIConnection"; the original connection is garbage-collected; 20 successive clones stay at 182 bytes of state. The new clone tests fail on 2bf79a5 (9 failures), so they catch the bug.
  • Early return: identical() tells distinct RSQLite connections, reference-class objects and environments apart, so it only skips a write when nothing would change; a different connection is written.
  • Outside the guard: inherits() works on an object whose class was removed, attr() is a primitive that does not dispatch, identical() does not error.
  • Docs on the class pages accurate; tests standalone, mocks undone.

Results: devtools::test(): FAIL 0, WARN 0, SKIP 60, PASS 9844 after 5942375. 20000 × dbExecute() on RSQLite (noisy machine): main 3.06–3.51 s, now 3.63–4.10 s, before the fixes 4.45–4.50 s; set_dbi_state() costs 6.8 µs per call, down from 24.9 µs.

Not checked: objects deserialized from an older DBI, backends other than RSQLite, a benchmark on a quiet machine.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by the current copy.

  • R/03-DBIConnection.R#L34-L39 (and the DBIResult and DBIResultArrow classes): a backend subclass that defines its own .dbi slot of another type fails to install against this DBI (question). Relevance low (a GitHub code search of CRAN found no such slot); reviewer confidence high.
  • R/dbi-state.R#L36-L54: a DBI-level argument that fails to evaluate is dropped silently, and duplicated names keep the last value (question). Relevance low until the first DBI-level argument exists; reviewer confidence high.
  • R/dbi-state.R#L61-L91: the bookkeeping adds about 7 µs per dbConnect(), dbSendQuery(), dbSendStatement() and dbSendQueryArrow() call, about 10% for a tight loop of dbExecute() on RSQLite :memory: (question). Relevance low next to a database round trip; reviewer confidence medium (noisy machine).
  • R/dbi-state.R#L61-L91: every connection and result now carries .dbi, so identical() comparisons and str()/dput() snapshots of connections and results change downstream, and serialized results grow by a copy of the connection (question). Relevance medium for downstream tests, to be checked in a reverse-dependency run; reviewer confidence high.

Generated by Claude Code

krlmlr pushed a commit that referenced this pull request Nov 29, 2026
The record under experiments/2026-11-29-s7/ tests S7 1.0.0 base classes and S7 generics
against installed S4 backends (RSQLite, duckdb, a minimal backend).
It also tests whether S7 properties avoid the class caching that makes #794 read its slot with attr().
S7 base classes registered with S4 keep installed backends working, but give #794 nothing:
backends see S4 classes, and new properties reach only reinstalled backends.
S7 generics break installed backends that define methods.

The scripts and their recorded output sit beside the record,
and .Rbuildignore now excludes experiments/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS
Comment thread R/dbConnect.R Resolved
@krlmlr

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Responded. The remaining question is only in scope for the follow-up.

The capture of arguments that DBI itself needs moves to a stacked pull request,
together with the R 4.1 requirement it introduced for `...names()` and `...elt()`.
The `dbConnect()` generic now keeps only its `drv` argument.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje
A connection created from a `DBIConnector` now keeps the inner driver,
so that every connection keeps a real driver
and the connector's arguments, which may contain credentials,
are not copied into connections and results.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Clean review of the merge of main, the move of the DBI-level arguments, and the connector change (5942375..a9659a1)

Scope: the merge of main (22e6efb, bringing #798 and #799), the removal of the DBI-level argument capture to the stacked #800 (bdcb0d1), and storing a connector's inner driver (a9659a1), as Kirill decided in the connector question. The rest of the PR was context. No High or Medium findings, so the review stops here.

Low

  1. A connector whose .drv was replaced with attr<- by a connector or a connection stores that object as is, so its credentials or the connection are kept again. The .drv slot only accepts a DBIDriver, so this needs a hand-built object. → Being fixed by unwrapping repeatedly.
  2. The DBIConnection docs say the connection keeps "its drv argument", which is no longer literal for a connector or a clone. → Being fixed with a pointer to ?dbConnect.
  3. A connector subclass with its own dbConnect() method that ignores @.drv still gets @.drv stored, not the driver it used. Theoretical; the docs say "the driver it wraps", which matches the code. → Question to follow.
  4. The test that no credentials are kept checks the stored value, not the serialized bytes. → Being fixed with a serialize() check.

Checked and correct

  • With an RSQLite connector carrying a password, serialize() of the connection, of a result and of a clone contains no secret at a9659a1 (it did at bdcb0d1). Arguments passed at call time are not kept either.
  • The stored drv is the inner driver for RSQLite, duckdb (including the dbSendQueryArrow() result) and a DBIConnector subclass; nested calls agree. A backend object without the slot gets the value and passes validObject().
  • No leftovers of the removed feature in R/, tests/, man/ or vignettes; nothing in the diff against main needs R 4.1, so R (>= 3.0.0) is consistent.
  • The merge: no semantic conflict; docs: Say which classes are virtual instead of all of them #798's "virtual classes" wording still holds for the classes with the slot. devtools::document() leaves no diff.
  • devtools::test() on R 4.5.3: 0 failures, 60 skips, 10021 expectations; every test_that() in the .dbi test files passes alone after load_all().

Not checked: a full R CMD check, older R versions, real backends with connector subclasses (e.g. odbc), the otel span.


Generated by Claude Code

Apply the unwrapping repeatedly, up to a small depth,
so that a connector whose `.drv` is itself a connector or a connection
does not keep credentials or a live connection.
Add tests that a connector's credentials are not serialized
with connections and results.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Question: For a connector subclass with its own dbConnect() method, keep @.drv or the driver the method used?

Found by the clean review (Low 3). dbi_connect_driver() stores a connector's .drv slot, whatever the connector's dbConnect() method does with it. A DBIConnector subclass whose method connects through another driver than @.drv therefore records @.drv, not the driver it used. No such subclass is known; the docs say "the driver it wraps", which matches the code.

  • Accept and keep @.drv (recommended): simple, documented, and never copies the connector's arguments; such a subclass is theoretical.
  • Let the inner dbConnect() call decide, by not overwriting a driver the inner call already stored: records the driver actually used, at the cost of a less obvious rule for nested calls.

Kirill decides. If nobody decides, @.drv is kept and this goes into the Accepted limitations.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by the current copy.

  • R/03-DBIConnection.R#L35-L40 (and the DBIResult and DBIResultArrow classes): a backend subclass that defines its own .dbi slot of another type fails to install against this DBI (question). Relevance low (a GitHub code search of CRAN found no such slot); reviewer confidence high.
  • R/dbi-state.R#L43-L73: the bookkeeping adds about 7 µs per dbConnect(), dbSendQuery(), dbSendStatement() and dbSendQueryArrow() call, about 10% for a tight loop of dbExecute() on RSQLite :memory: (question). Relevance low next to a database round trip; reviewer confidence medium (noisy machine).
  • R/dbi-state.R#L43-L73: every connection and result now carries .dbi, so identical() comparisons and str()/dput() snapshots of connections and results change downstream, and serialized results grow by a copy of the connection (question, accepted by Kirill). Relevance medium for downstream tests, to be checked in a reverse-dependency run; reviewer confidence high.
  • R/dbi-state.R#L19-L37: a connector subclass whose dbConnect() method ignores @.drv still gets @.drv stored (question). Relevance very low (no such subclass known); reviewer confidence high.

The limitation about DBI-level arguments that fail to evaluate moved to #800 with that code.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Question: Accept that objects saved before a backend is reinstalled fail validObject(), or declare no slot at all?

Found by the experiment in #802 (record). The slot declaration on DBIConnection (and DBIResult, DBIResultArrow) reaches a backend's classes only when the backend is reinstalled. Until then, [email protected] works on objects from DBI's generics, which set the attribute, but fails on objects made with new() or saved with saveRDS() before: no slot of name ".dbi" for this object of class "MiniConnection". After the backend is reinstalled, objects saved before still fail @, and now also validObject(): invalid class “MiniConnection” object: slots in class definition but not in object: ".dbi". attr(x, ".dbi", exact = TRUE) never errors; it returns NULL where the attribute is missing.

  • Accept, and say in NEWS that objects saved before the upgrade fail validObject() once the backend is reinstalled (recommended): connections and results do not survive serialization anyway (RSQLite's fail with bad_weak_ptr with either DBI), and the slot keeps @, str() and the class docs honest for reinstalled backends.
  • Declare no slot, and keep .dbi as a plain attribute set and read with attr() only: no class definition changes, so no validObject() failure and no clash with a backend's own .dbi slot (question), at the cost of [email protected] never being documented and str() not showing it as a slot.

Kirill decides. If nobody decides, the slot stays and this goes into the Accepted limitations.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations

Superseded by the current copy.

  • R/03-DBIConnection.R#L35-L40 (and the DBIResult and DBIResultArrow classes): a backend subclass that defines its own .dbi slot of another type fails to install against this DBI (question). Relevance low (a GitHub code search of CRAN found no such slot); reviewer confidence high.

  • R/dbi-state.R#L43-L73: the bookkeeping adds about 7 µs per dbConnect(), dbSendQuery(), dbSendStatement() and dbSendQueryArrow() call, about 10% for a tight loop of dbExecute() on RSQLite :memory: (question). Relevance low next to a database round trip; reviewer confidence medium (noisy machine).

  • R/dbi-state.R#L43-L73: every connection and result now carries .dbi, so identical() comparisons and str()/dput() snapshots of connections and results change downstream, and serialized results grow by a copy of the connection (question, accepted by Kirill). Relevance medium for downstream tests, to be checked in a reverse-dependency run; reviewer confidence high.

  • R/dbi-state.R#L19-L37: a connector subclass whose dbConnect() method ignores @.drv still gets @.drv stored (question). Relevance very low (no such subclass known); reviewer confidence high.

  • R/03-DBIConnection.R#L35-L40: objects made with new() or saved before the upgrade lack the attribute, so @.dbi fails on them, and once the backend is reinstalled, objects saved before also fail validObject() (question, experiment in docs: Record what fails for backends installed against DBI without the .dbi slot #802). Relevance low (connections and results do not survive serialization anyway); reviewer confidence high.

The limitation about DBI-level arguments that fail to evaluate moved to #800 with that code.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

How the slot question interacts with a move to S7

Kirill asked how the slot question interacts with the move to S7 investigated in #795, and whether there will be slots. From the two S7 records on the branch of #795 and the experiment in #802:

  • Yes, there would still be slots, in the backends. With S7, .dbi becomes an S7 property of DBIConnection (as in both S7 records: first, vendored). Backends stay S4 classes that extend the registered S7 class, and their S4 class definitions carry the property as an ordinary slot. S7 itself stores properties as attributes, so the value lives in the same .dbi attribute as with the S4 slot of this PR.
  • The install-time problem is the same. A new property reaches only backends reinstalled against the new DBI, exactly like a new slot: installed against main, [email protected] fails with "no slot of name" (record); with the adapted S7, prop(con, ".dbi") and [email protected] work only for classes installed against the S7 DBI (record). S7 also caches parent properties in S7 subclasses, so even a backend rewritten in S7 needs reinstalling to see a new property (record). Both records conclude that attr(x, ".dbi") stays the access path under S7 (first).
  • .dbi cannot be a computed property. A property with a getter does not reach S4 subclasses at all (record), so it has to be a stored value, as now.
  • What this means for the two options of the slot question:
    • Keeping the slot: a later move to S7 declares a property of the same name and type (class_list), stored in the same attribute, so objects made under this PR need no conversion, and backends reinstalled for this PR already have the slot. The validObject() failure for objects saved before the reinstall happens once, now, rather than at the S7 move.
    • Declaring no slot: nothing changes in class definitions now; if the S7 move later declares .dbi as a property, the same transition, including the validObject() failure for older saved objects, happens then. If the S7 move also keeps .dbi undeclared, it never happens.
    • Either way, code reads .dbi with attr() for as long as backends installed against an older DBI are around, under S4 or S7.
  • Not tested: validObject() or S7's validate() on objects saved before a backend was reinstalled against an S7 DBI, and S7 objects (not S4 subclasses) deserialized without the attribute.

So the S7 move does not resolve the slot question: it inherits it. The recommendation on the slot question stands; the S7 investigation adds that keeping the slot aligns with how S7 would declare .dbi.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

  • R/03-DBIConnection.R#L35-L40 (and the DBIResult and DBIResultArrow classes): a backend subclass that defines its own .dbi slot of another type fails to install against this DBI (question). Relevance low (a GitHub code search of CRAN found no such slot); reviewer confidence high.

  • R/dbi-state.R#L43-L73: the bookkeeping adds about 7 µs per dbConnect(), dbSendQuery(), dbSendStatement() and dbSendQueryArrow() call, about 10% for a tight loop of dbExecute() on RSQLite :memory: (question). Relevance low next to a database round trip; reviewer confidence medium (noisy machine).

  • R/dbi-state.R#L43-L73: every connection and result now carries .dbi, so identical() comparisons and str()/dput() snapshots of connections and results change downstream, and serialized results grow by a copy of the connection (question, accepted by Kirill). Relevance medium for downstream tests, to be checked in a reverse-dependency run; reviewer confidence high.

  • R/dbi-state.R#L19-L37: a connector subclass whose dbConnect() method ignores @.drv still gets @.drv stored (question). Relevance very low (no such subclass known); reviewer confidence high.

  • R/03-DBIConnection.R#L35-L40: objects made with new() or saved before the upgrade lack the attribute, so @.dbi fails on them, and once the backend is reinstalled, objects saved before also fail validObject() (question, experiment in docs: Record what fails for backends installed against DBI without the .dbi slot #802). Relevance low (connections and results do not survive serialization anyway); reviewer confidence high.

The limitation about DBI-level arguments that fail to evaluate moved to #800 with that code.


Generated by Claude Code

This branch has not been deployed

No deployments
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