{"record":{"id":"ff66b2e2c8463176","repo":"redis/redis-py","slug":"xadd-fields-must-be-a-non-empty-dict","errorCode":null,"errorMessage":"XADD fields must be a non-empty dict","messagePattern":"XADD fields must be a non-empty dict","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":7055,"sourceCode":"                )\n            pieces.extend([b\"IDMP\", idmp[0], idmp[1]])\n        if maxlen is not None:\n            if not isinstance(maxlen, int) or maxlen < 0:\n                raise DataError(\"XADD maxlen must be non-negative integer\")\n            pieces.append(b\"MAXLEN\")\n            if approximate:\n                pieces.append(b\"~\")\n            pieces.append(str(maxlen))\n        if minid is not None:\n            pieces.append(b\"MINID\")\n            if approximate:\n                pieces.append(b\"~\")\n            pieces.append(minid)\n        if limit is not None:\n            pieces.extend([b\"LIMIT\", limit])\n        pieces.append(id)\n        if not isinstance(fields, dict) or len(fields) == 0:\n            raise DataError(\"XADD fields must be a non-empty dict\")\n        for pair in fields.items():\n            pieces.extend(pair)\n        return self.execute_command(\"XADD\", name, *pieces)\n\n    @overload\n    def xcfgset(\n        self: SyncClientProtocol,\n        name: KeyT,\n        idmp_duration: int | None = None,\n        idmp_maxsize: int | None = None,\n    ) -> bytes | str: ...\n\n    @overload\n    def xcfgset(\n        self: AsyncClientProtocol,\n        name: KeyT,\n        idmp_duration: int | None = None,\n        idmp_maxsize: int | None = None,","sourceCodeStart":7037,"sourceCodeEnd":7073,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/core.py#L7037-L7073","documentation":"Raised by xadd() when fields is not a dict or is an empty dict. XADD requires at least one field/value pair in the stream entry; passing a list, None, or {} is invalid. It is a DataError.","triggerScenarios":"Calling client.xadd('mystream', {}), client.xadd('mystream', [('f', 'v')]) (list of pairs), or client.xadd('mystream', None).","commonSituations":"Building fields from a query/result that produced no rows, or passing a list of tuples instead of a dict.","solutions":["Pass a non-empty dict of field/value pairs, e.g. {'field1': 'value1'}.","If the dict may be empty at runtime, guard with 'if fields:' before calling xadd."],"exampleFix":"# before\nclient.xadd('mystream', {})\n\n# after\nclient.xadd('mystream', {'field1': 'value1'})","handlingStrategy":"type-guard","validationCode":"if not isinstance(fields, dict) or not fields:\n    raise ValueError('fields must be a non-empty dict')\nclient.xadd(name, fields)","typeGuard":"def is_valid_fields(v) -> bool:\n    return isinstance(v, dict) and len(v) > 0\n\n# usage\nif not is_valid_fields(fields):\n    raise TypeError('fields must be a non-empty dict')","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.xadd(name, fields)\nexcept DataError as e:\n    if 'fields must be a non-empty dict' in str(e):\n        fields = {'placeholder': '1'}\n        client.xadd(name, fields)","preventionTips":["Guard dynamically-built field dicts with 'if fields:' before calling xadd.","Convert list-of-pairs to dict with dict(pairs) and ensure it is non-empty."],"tags":["streams","xadd","required-argument","type-check","validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}