Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/onlyworlds/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.138.2"
__version__ = "0.139.0"
11 changes: 10 additions & 1 deletion src/onlyworlds/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading