diff --git a/CHANGELOG.md b/CHANGELOG.md index cf1c921..ebef00a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The package version runs on its own semver; the schema it is generated from is ` ## Unreleased +## 0.139.0 (2026-11-21) + +- **`bulk(items, create_only=True)`**, sent as `create_only`: every item with an `id` is created as `create` creates it, never replaced. An id the world already holds answers that item's slot `409` `id_conflict`, and the element stays as it was; the rest of the batch goes on as before. Left `False`, the body is the one earlier releases sent; a value that is not a bool is refused before anything is sent. + ## 0.138.2 (2026-11-21) - **`push` never sends `atlas_baseline_unknown`.** Atlas 1.124.30 marks a copy whose stamp came from OnlyWorlds with no record of what OnlyWorlds held, and keeps that mark on the device only. A folder Atlas wrote can carry it; `push` now leaves it out of every patch, as it does Atlas's other local-only fields. diff --git a/src/onlyworlds/_version.py b/src/onlyworlds/_version.py index ec9615a..99ac4c4 100644 --- a/src/onlyworlds/_version.py +++ b/src/onlyworlds/_version.py @@ -1 +1 @@ -__version__ = "0.138.2" +__version__ = "0.139.0" diff --git a/src/onlyworlds/http.py b/src/onlyworlds/http.py index 8707408..027e2cc 100644 --- a/src/onlyworlds/http.py +++ b/src/onlyworlds/http.py @@ -1134,6 +1134,7 @@ def bulk( *, atomic: bool = False, idempotency_key: str | None = None, + create_only: bool = False, ) -> BulkResult: """``POST /bulk``: up to about 1,000 ``{"type", "element"}`` items. @@ -1146,7 +1147,13 @@ def bulk( ``hidden`` is sent as each element has it: an item that creates with ``hidden: true`` is created hidden; from a key that may not hide, that slot is a 403 ``hidden_not_allowed`` and its element is not created, the other slots as ever. + + ``create_only=True`` (sent as ``create_only``) creates every item with an ``id`` as ``create`` + does, never replacing it: an id the world already holds answers that slot 409 ``id_conflict`` + and the element stays as it was. Left False, the body is the one earlier releases sent. """ + if not isinstance(create_only, bool): + raise TypeError("bulk: create_only is True or False. Nothing was sent.") elements = [] for index, it in enumerate(items): _refuse_known_of(it["element"], f"bulk: items[{index}]") # the whole call, never a skipped slot @@ -1155,10 +1162,12 @@ def bulk( if not element.get("id"): element["id"] = _minted_id(idempotency_key, index) elements.append({"type": _segment(str(it["type"]), _TYPE, "element type"), "element": element}) - body = { + body: dict[str, Any] = { "items": elements, "atomic": atomic, } + if create_only: + body["create_only"] = True key = idempotency_key or str(uuid.uuid4()) got = self.send("POST", "bulk/", body, self._writing({"Idempotency-Key": key})) if got.response is None: diff --git a/tests/test_client.py b/tests/test_client.py index 52fe523..f02b330 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -262,6 +262,23 @@ def test_bulk_body_flag_key_and_replay(make_client: MakeClient) -> None: assert c.bulk([]).was_replay is False +def test_bulk_create_only_is_sent_only_when_true(make_client: MakeClient) -> None: + ok = {"errors": False, "items": [{"status": 201, "id": "a"}]} + t = FakeTransport(script=[jresp(200, ok), jresp(200, ok), jresp(200, ok)]) + c = make_client(t) + items = [{"type": "character", "element": {"id": "mine", "name": "A"}}] + c.bulk(items, create_only=True) + assert list(t.calls[-1].body) == ["items", "atomic", "create_only"] and t.calls[-1].body["create_only"] is True + c.bulk(items) + c.bulk(items, create_only=False) + assert [list(call.body) for call in t.calls[-2:]] == [["items", "atomic"]] * 2 + sent = len(t.calls) + for bad in ("true", 1, None): + with pytest.raises(TypeError, match="create_only is True or False"): + c.bulk(items, create_only=bad) # type: ignore[arg-type] + assert len(t.calls) == sent # a refused create_only sends nothing + + def test_bulk_resend_after_a_lost_answer_names_the_same_elements(make_client: MakeClient) -> None: """keel stores a bulk answer only after the batch commits: a 502 after the commit replays nothing, so an id-less item resent as id-less would be created twice. Ids given are kept."""