DuckDB ResourceInUseException when using duckdb.sql() in Marimo
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
Research direction
Start with the DuckDB relation formatting path named in the report: marimo/_output/formatting.py and marimo/_output/formatters/repr_formatters.py. Reproduce with the provided DataFrame and duckdb.sql() example, then compare it with a query through duckdb.connect(). Done when automatic display succeeds for the sql() result without raising ResourceInUseException.
Written by the indexing model from the issue text.
Description
Describe the bug
I'm experiencing a ResourceInUseException when executing SQL queries using duckdb.sql() in Marimo.
The issue occurs when Marimo attempts to automatically format and display the resulting DuckDB Relation.
Interestingly, the same queries work as expected when using an explicit connection created with duckdb.connect().
Steps to Reproduce
Create a Pandas DataFrame.
Execute a SQL query using duckdb.sql().
Allow Marimo to automatically display the resulting relation.
Example:
import duckdb
import pandas as pd
df = pd.DataFrame({
"id": [1, 2, 3],
"value": [10, 20, 30]
})
result = duckdb.sql("""
SELECT *
FROM df
""")
result
Expected Behavior
The SQL query should execute successfully, and Marimo should display the resulting relation without raising an exception.
Actual Behavior
Marimo raises the following exception when attempting to format the DuckDB Relation:
_duckdb.ResourceInUseException: Resource In Use Error:
connection has an unfinished result from execute();
call complete() or abort(), or fetch until a fetch returns
no rows, before other work on this connection,
or use a separate connection from cursor()
The traceback points to Marimo's automatic formatting process:
marimo/_output/formatting.py
marimo/_output/formatters/repr_formatters.py
duckdb/_relation.py
Additional Findings
After testing different approaches, I noticed that:
The issue occurs when using duckdb.sql().
The same query works correctly when using duckdb.connect() and executing the query through the connection.
The exception appears during the automatic formatting/display of the DuckDB Relation in Marimo.
Environment
OS: Windows
Python: 3.15
Notebook environment: Marimo
Database engine: DuckDB
Question
Could this be related to how Marimo handles or formats DuckDB Relation objects returned by duckdb.sql(), particularly when the underlying connection has an unfinished result?
Is this an expected DuckDB limitation or a potential compatibility issue between DuckDB's relation handling and Marimo's reactive execution/display mechanism?
Will you submit a PR?
- Yes
Environment
{
"marimo": "0.25.2",
"editable": false,
"location": "C:/Users/user/AppData/Local/Python/pythoncore-3.15-64/Lib/site-packages/marimo",
"OS": "Windows",
"OS Version": "11",
"Processor": "Intel64 Family 6 Model 142 Stepping 12, GenuineIntel",
"Python Version": "3.15.0",
"Locale": "English_United States",
"Binaries": {
"Browser": "157.0.8103.79",
"Node": "--",
"uv": "0.13.7 (316c827e0 2026-11-03 x86_64-pc-windows-msvc)"
},
"Dependencies": {
"click": "8.5.1",
"docutils": "0.23",
"itsdangerous": "2.2.0",
"jedi": "0.20.1",
"markdown": "3.11.3",
"narwhals": "2.28.0",
"packaging": "26.3",
"psutil": "7.2.2",
"pygments": "2.21.0",
"pymdown-extensions": "11.0.2",
"pyyaml": "6.0.3",
"starlette": "1.10.0",
"tomlkit": "0.15.2",
"typing-extensions": "4.16.0",
"uvicorn": "0.54.0",
"websockets": "17.4"
},
"Optional Dependencies": {
"altair": "6.3.0",
"anywidget": "0.11.0",
"duckdb": "2.0.0",
"mcp": "2.3.0",
"nbformat": "5.11.1",
"openai": "3.51.0",
"pandas": "3.1.1",
"polars": "2.1.0",
"pyarrow": "26.0.0",
"pytest": "9.1.1",
"python-lsp-ruff": "2.3.4",
"python-lsp-server": "1.15.0",
"ruff": "0.17.0",
"sqlglot": "30.31.0",
"vegafusion": "2.0.3"
},
"Experimental Flags": {}
}
Code to reproduce
import duckdb as db
db.sql('select * from df')
- Dominant language
- Python
- Stars
- 22.9k
- Forks
- 1.3k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 380
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from marimo-team/marimo
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
marimo-team/marimo#12027 ·
Maintainers usually reply within 1 day
-
"Clamp all outputs" leaves cells without output marked `expand_output: true`Possibly taken @marthacryan claimed this 12 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
marimo-team/marimo#11768 · 1 assignee ·
Maintainers usually reply within 1 day
-
Cell referencing a variable from a "cancelled" cell runs and raises NameError instead of being blockedMay be free again @dmadisetti claimed this 33 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
marimo-team/marimo#11307 · 1 assignee ·
Maintainers usually reply within 1 day
-
molab
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
marimo-team/marimo#11298 · 1 comment ·
Maintainers usually reply within 1 day
-
Theme change does not affect terminal colorsMay be free again @CloudCorpRecords claimed this 36 days ago, and no pull request is open. Openneeds discussion
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
marimo-team/marimo#11244 · 4 comments ·
Maintainers usually reply within 1 day
All issues in marimo-team/marimo
Similar issues
-
run_gate loads a custom tasks file from outside the working directoryPossibly taken @Ru0k3 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MakazhanAlpamys/Soup#3189 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
nautechsystems/nautilus_trader#5741 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
huggingface/datasets#9128 ·
Maintainers usually reply within 1 day