{"record":{"id":"09ebf0d1333fd588","repo":"chroma-core/chroma","slug":"invalid-conditional-transaction-for-http-client","errorCode":null,"errorMessage":"invalid conditional transaction for HTTP client","messagePattern":"invalid conditional transaction for HTTP client","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/conditional_http.py","lineNumber":319,"sourceCode":"                \"proving the id is absent\"\n            )\n        if operation == \"update\" and id not in self._known_present:\n            raise InvalidArgumentError(\n                f'transactional update for id \"{id}\" requires a prior read '\n                \"proving the id is present\"\n            )\n        if operation == \"delete\" and id not in self._known_present:\n            raise InvalidArgumentError(\n                f'transactional delete for id \"{id}\" requires a prior read '\n                \"proving the id is present\"\n            )\n\n\ndef require_conditional_http_transaction(\n    transaction: object,\n) -> ConditionalHttpTransaction:\n    if not isinstance(transaction, ConditionalHttpTransaction):\n        raise ValueError(\"invalid conditional transaction for HTTP client\")\n    return transaction\n\n\ndef _invalid_read_after_write(id: str) -> InvalidArgumentError:\n    return InvalidArgumentError(\n        f'cannot transactionally read id \"{id}\" after buffering a write for it'\n    )\n","sourceCodeStart":301,"sourceCodeEnd":327,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/conditional_http.py#L301-L327","documentation":"require_conditional_http_transaction (chromadb/api/conditional_http.py:319) raises this ValueError when the transaction object handed to the HTTP client's conditional-transaction methods is not a ConditionalHttpTransaction instance. The client refuses any substitute - a dict, None, a mock, or a transaction object from another client implementation - because it drives the transaction's internal buffers (scope, read sets, buffered operations) directly.","triggerScenarios":"Passing a hand-constructed object, dict, or None where the HTTP client expects the ConditionalHttpTransaction returned by its own begin/create-transaction call; mixing transaction objects between an AsyncClient or other API implementation and the sync HTTP client; test doubles replacing the transaction.","commonSituations":"Wrapper libraries or ORMs building their own transaction abstraction over chromadb; copy-pasting code across client types (segment/local vs http); mocking in unit tests leaking into integration paths.","solutions":["Always obtain the transaction from the same HTTP client instance you commit with (its begin/create transaction API)","Type-check before passing: isinstance(transaction, ConditionalHttpTransaction)","In tests, keep fakes behind your own interface, not at the chromadb transaction boundary"],"exampleFix":"# before\ntxn = {\"operations\": []}              # not a real transaction\nclient._commit_conditional(txn)      # ValueError\n# after\ntxn = client.create_transaction()    # ConditionalHttpTransaction from the client\nclient._commit_conditional(txn)","handlingStrategy":"type-guard","validationCode":"from chromadb.api.conditional_http import ConditionalHttpTransaction\n\ndef commit_txn(client, txn):\n    if not isinstance(txn, ConditionalHttpTransaction):\n        raise TypeError(\"txn must come from the HTTP client's transaction API\")\n    return client._commit_conditional(txn)","typeGuard":"from chromadb.api.conditional_http import ConditionalHttpTransaction\nfrom typing import Any\n\ndef is_conditional_http_transaction(obj: Any) -> bool:\n    \"\"\"Type guard: True when obj is a ConditionalHttpTransaction.\"\"\"\n    return isinstance(obj, ConditionalHttpTransaction)","tryCatchPattern":"try:\n    require_conditional_http_transaction(txn)\nexcept ValueError as e:\n    if \"invalid conditional transaction\" in str(e):\n        txn = client.create_transaction()  # start a real one\n    else:\n        raise","preventionTips":["Obtain the transaction from the same HTTP client you commit with","Never substitute dicts, mocks, or other clients' transaction objects at the chromadb boundary","Keep test fakes behind your own abstraction, not inside chromadb calls"],"tags":["chromadb","transaction","http-client","type-check"],"backgroundTag":"transaction-validation-failed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}