-
-
Notifications
You must be signed in to change notification settings - Fork 813
Closed
Description
This flaky test only affects SQLite 3.25.3 and only for Python 3.10 and 3.12:
_______________ test_upsert[True-initial0-input0-expected_rows0] _______________
[gw1] linux -- Python 3.10.19 /opt/hostedtoolcache/Python/3.10.19/x64/bin/python
ds_write = <datasette.app.Datasette object at 0x7ff30b42a5c0>
initial = {'pk': 'id', 'rows': [{'id': 1, 'title': 'One'}], 'table': 'upsert_test'}
input = {'return': True, 'rows': [{'id': 1, 'title': 'Two'}]}
expected_rows = [{'id': 1, 'title': 'Two'}], should_return = True
@pytest.mark.asyncio
@pytest.mark.parametrize(
"initial,input,expected_rows",
(
(
# Simple primary key update
{"rows": [{"id": 1, "title": "One"}], "pk": "id"},
{"rows": [{"id": 1, "title": "Two"}]},
[
{"id": 1, "title": "Two"},
],
),
(
# Multiple rows update one of them
{
"rows": [{"id": 1, "title": "One"}, {"id": 2, "title": "Two"}],
"pk": "id",
},
{"rows": [{"id": 1, "title": "Three"}]},
[
{"id": 1, "title": "Three"},
{"id": 2, "title": "Two"},
],
),
(
# rowid update
{"rows": [{"title": "One"}]},
{"rows": [{"rowid": 1, "title": "Two"}]},
[
{"rowid": 1, "title": "Two"},
],
),
(
# Compound primary key update
{"rows": [{"id": 1, "title": "One", "score": 1}], "pks": ["id", "score"]},
{"rows": [{"id": 1, "title": "Two", "score": 1}]},
[
{"id": 1, "title": "Two", "score": 1},
],
),
(
# Upsert with an alter
{"rows": [{"id": 1, "title": "One"}], "pk": "id"},
{"rows": [{"id": 1, "title": "Two", "extra": "extra"}], "alter": True},
[{"id": 1, "title": "Two", "extra": "extra"}],
),
),
)
@pytest.mark.parametrize("should_return", (False, True))
async def test_upsert(ds_write, initial, input, expected_rows, should_return):
token = write_token(ds_write)
# Insert initial data
initial["table"] = "upsert_test"
create_response = await ds_write.client.post(
"/data/-/create",
json=initial,
headers=_headers(token),
)
assert create_response.status_code == 201
if should_return:
input["return"] = True
response = await ds_write.client.post(
"/data/upsert_test/-/upsert",
json=input,
headers=_headers(token),
)
> assert response.status_code == 200, response.text
E AssertionError: {"ok": false, "errors": ["Row 0 is missing primary key column(s): \"rowid\""]}
E assert 400 == 200
E + where 400 = <Response [400 Bad Request]>.status_code
Originally posted by @simonw in #2626 (comment)
Reactions are currently unavailable