Skip to content

Conversation

@gadenbuie
Copy link
Contributor

Prior to this PR, if you pass in a database connection to querychat_app() it will close your connection for you. You only would want that if querychat created the table connection internally, i.e. if you passed in a data.frame.

Before

pkgload::load_all()

con <- DBI::dbConnect(duckdb::duckdb())
duckdb::dbWriteTable(con, "mtcars", mtcars)

querychat_app(con, "mtcars")
#> Closing data source...

DBI::dbGetQuery(con, "SELECT * FROM mtcars LIMIT 5;")
#> Error in `dbSendQuery()`:
#> ! Invalid connection
#> ℹ Context: rapi_prepare

After

The database connection remains intact and the dbGetQuery() call completes as expected.

@gadenbuie gadenbuie requested a review from cpsievert December 10, 2025 21:44
Comment on lines 678 to 685
if (is.na(cleanup) && interactive() && !in_shiny_session()) {
if (
is.data.frame(data_source) ||
inherits(data_source, "DataFrameSource")
) {
cleanup <- TRUE
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do the analogous thing for Python?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out Python didn't have a cleanup parameter, so I added that to QueryChat.

Python doesn't have a querychat_app() function, which highlights that this is a special case. I also updated the implementation slightly: we now only clean up if we're given a data.frame that we are turning into a data source. Otherwise, calling $cleanup() destructively ruins a DataSource object, which isn't great.

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.

3 participants