mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Don't include columns in query JSON, refs #2136
This commit is contained in:
parent
8920d425f4
commit
e34d09c6ec
4 changed files with 14 additions and 8 deletions
|
|
@ -27,7 +27,7 @@ def convert_specific_columns_to_json(rows, columns, json_cols):
|
||||||
return new_rows
|
return new_rows
|
||||||
|
|
||||||
|
|
||||||
def json_renderer(args, data, error, truncated=None):
|
def json_renderer(request, args, data, error, truncated=None):
|
||||||
"""Render a response as JSON"""
|
"""Render a response as JSON"""
|
||||||
status_code = 200
|
status_code = 200
|
||||||
|
|
||||||
|
|
@ -106,6 +106,12 @@ def json_renderer(args, data, error, truncated=None):
|
||||||
"status": 400,
|
"status": 400,
|
||||||
"title": None,
|
"title": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Don't include "columns" in output
|
||||||
|
# https://github.com/simonw/datasette/issues/2136
|
||||||
|
if isinstance(data, dict) and "columns" not in request.args.getlist("_extra"):
|
||||||
|
data.pop("columns", None)
|
||||||
|
|
||||||
# Handle _nl option for _shape=array
|
# Handle _nl option for _shape=array
|
||||||
nl = args.get("_nl", "")
|
nl = args.get("_nl", "")
|
||||||
if nl and shape == "array":
|
if nl and shape == "array":
|
||||||
|
|
|
||||||
|
|
@ -548,7 +548,7 @@ class QueryView(View):
|
||||||
error=query_error,
|
error=query_error,
|
||||||
# These will be deprecated in Datasette 1.0:
|
# These will be deprecated in Datasette 1.0:
|
||||||
args=request.args,
|
args=request.args,
|
||||||
data={"rows": rows, "columns": columns},
|
data={"ok": True, "rows": rows, "columns": columns},
|
||||||
)
|
)
|
||||||
if asyncio.iscoroutine(result):
|
if asyncio.iscoroutine(result):
|
||||||
result = await result
|
result = await result
|
||||||
|
|
|
||||||
|
|
@ -649,7 +649,6 @@ async def test_custom_sql(ds_client):
|
||||||
{"content": "RENDER_CELL_DEMO"},
|
{"content": "RENDER_CELL_DEMO"},
|
||||||
{"content": "RENDER_CELL_ASYNC"},
|
{"content": "RENDER_CELL_ASYNC"},
|
||||||
],
|
],
|
||||||
"columns": ["content"],
|
|
||||||
"ok": True,
|
"ok": True,
|
||||||
"truncated": False,
|
"truncated": False,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,12 @@ def test_serve_with_get(tmp_path_factory):
|
||||||
"/_memory.json?sql=select+sqlite_version()",
|
"/_memory.json?sql=select+sqlite_version()",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
assert 0 == result.exit_code, result.output
|
assert result.exit_code == 0, result.output
|
||||||
assert {
|
data = json.loads(result.output)
|
||||||
"truncated": False,
|
# Should have a single row with a single column
|
||||||
"columns": ["sqlite_version()"],
|
assert len(data["rows"]) == 1
|
||||||
}.items() <= json.loads(result.output).items()
|
assert list(data["rows"][0].keys()) == ["sqlite_version()"]
|
||||||
|
assert set(data.keys()) == {"rows", "ok", "truncated"}
|
||||||
|
|
||||||
# The plugin should have created hello.txt
|
# The plugin should have created hello.txt
|
||||||
assert (plugins_dir / "hello.txt").read_text() == "hello"
|
assert (plugins_dir / "hello.txt").read_text() == "hello"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue