Skip to content

Commit cc5fa7d

Browse files
authored
fix issue where passing None as parameter to a query would fail (#8)
1 parent 096bb62 commit cc5fa7d

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

tests/integration/test_pipes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ def test_query_with_params(self, client):
126126
response = client.api.pipes.query("simple_pipe", parameters={"key": "does not exist"})
127127
assert response.data == []
128128

129+
# test with none parameters
130+
response = client.api.pipes.query("simple_pipe", parameters={"key": None})
131+
# simple check to make sure it returned all items
132+
assert [(record["key"], record["value"]) for record in response.data] == [
133+
("foo", "bar"),
134+
("baz", "ed"),
135+
("foo", "bar2"),
136+
]
137+
129138
def test_query_with_sql(self, client):
130139
client.api.events.send(
131140
"simple",

tests/integration/test_query.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ def test_query_pipe_parameters(self, client):
5858
assert response.rows == 1
5959
assert response.statistics["rows_read"] == 2
6060

61+
def test_query_pipe_with_none_parameters(self, client):
62+
response = client.api.query.query(
63+
"SELECT key, value FROM simple_pipe ORDER BY key ASC", parameters={"key": None}
64+
)
65+
66+
assert response.data == [{"key": "baz", "value": "ed"}, {"key": "foo", "value": "bar"}]
67+
assert response.meta == [
68+
{"name": "key", "type": "String"},
69+
{"name": "value", "type": "String"},
70+
]
71+
assert response.rows == 2
72+
assert response.statistics["rows_read"] == 2
73+
6174
def test_query_pipeline_json(self, client):
6275
response = client.api.query.query(
6376
"SELECT * FROM _ ORDER BY `key` ASC", pipeline="simple_kv"

verdin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name = "verdin"
22

3-
__version__ = "0.5.1"
3+
__version__ = "0.5.2"

verdin/api/pipes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def query(
230230
self,
231231
name: str,
232232
query: str = None,
233-
parameters: dict[str, str] = None,
233+
parameters: dict[str, str | None] = None,
234234
format: PipeOutputFormat = "json",
235235
) -> QueryPipeResponse | QueryPipeJsonResponse | QueryPipeNdjsonResponse | QueryPipeCsvResponse:
236236
"""
@@ -256,6 +256,8 @@ def query(
256256
# this limit is around 8kb, so if it's too large, we use a POST request instead.
257257
qsize = 1 # include the "?" character
258258
for k, v in params.items():
259+
if v is None:
260+
continue
259261
qsize += len(k) + len(v) + 2 # include the ``&`` and ``=`` character
260262

261263
if qsize > 8192:

verdin/api/query.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def query(
161161
self,
162162
query: str,
163163
pipeline: str = None,
164-
parameters: dict[str, str] = None,
164+
parameters: dict[str, str | None] = None,
165165
output_format_json_quote_64bit_integers: bool = False,
166166
output_format_json_quote_denormals: bool = False,
167167
output_format_parquet_string_as_string: bool = False,
@@ -216,6 +216,8 @@ def query(
216216
# this limit is around 8kb, so if it's too large, we use a POST request instead.
217217
qsize = 1 # include the "?" character
218218
for k, v in data.items():
219+
if v is None:
220+
continue
219221
qsize += len(k) + len(v) + 2 # include the ``&`` and ``=`` character
220222

221223
if qsize > 8192 or parameters:

verdin/test/container.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99

1010
class TinybirdLocalContainer:
11+
# TODO: easier configuration of compatibility mode
12+
1113
def __init__(self, cwd: str = None):
1214
"""
1315
Creates a new TinybirdLocalContainer instance.

0 commit comments

Comments
 (0)