{"record":{"id":"a7672b2f839fca60","repo":"xai-org/x-algorithm","slug":"acks-must-be-0-1-or-all-got-self-acks-r","errorCode":null,"errorMessage":"acks must be 0, 1, or 'all', got {self.acks!r}","messagePattern":"acks must be 0, 1, or 'all', got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"grox/libs/kafka_cli/multi_region_producer.py","lineNumber":30,"sourceCode":"\nRETRY_FAILED_REGION_INTERVAL_SEC = 60\n\n\nclass MultiRegionKafkaProducerConfig(BaseModel):\n    topic: str\n    clusters: dict[str, list[str]]\n    acks: int | str = Field(default=1)\n    request_timeout_ms: int = Field(default=30000)\n\n    @model_validator(mode=\"after\")\n    def _validate(self) -> \"MultiRegionKafkaProducerConfig\":\n        if not self.clusters:\n            raise ValueError(\"`clusters` must contain at least one region\")\n        for region, brokers in self.clusters.items():\n            if not brokers:\n                raise ValueError(f\"Region {region!r} must list at least one broker\")\n        if self.acks not in (0, 1, \"all\"):\n            raise ValueError(f\"acks must be 0, 1, or 'all', got {self.acks!r}\")\n        return self\n\n\nclass MultiRegionKafkaProducer:\n    def __init__(self, config: MultiRegionKafkaProducerConfig):\n        self.config = config\n        self.topic: str = config.topic\n        self._producers: dict[str, AIOKafkaProducer] = {}\n        self._region_retry_task: asyncio.Task | None = None\n\n    async def start(self):\n        regions = list(self.config.clusters.items())\n        try:\n            results = await asyncio.gather(\n                *[self._start_region(region, brokers) for region, brokers in regions],\n                return_exceptions=True,\n            )\n        except BaseException:","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/grox/libs/kafka_cli/multi_region_producer.py#L12-L48","documentation":"The producer config validator whitelists acks to the Kafka-legal values 0, 1, or the string 'all'. Anything else — including the int 2, '1', or -1 — fails with a message echoing the offending value, because aiokafka would otherwise reject or misinterpret it at runtime.","triggerScenarios":"MultiRegionKafkaProducerConfig(acks=2), acks='1' (string digit), acks=-1 (old-style alias for all), or a YAML value parsed as the wrong type.","commonSituations":"Translating Java Kafka configs where acks=-1/acks=all conventions differ; YAML unquoted all being fine but numeric strings like '1' coming from env vars being str not int; copying a config that worked with a different client library.","solutions":["Use acks=1 (int) for default durability, acks=0 for fire-and-forget, or acks='all' (exact string) for full replication acks.","If the value comes from an env var, normalize it: int(v) if v.isdigit() else v.","Remove -1 aliases; this library does not map them."],"exampleFix":"# before\ncfg = MultiRegionKafkaProducerConfig(clusters={...}, acks=-1)  # ValueError\n\n# after\ncfg = MultiRegionKafkaProducerConfig(clusters={...}, acks='all')","handlingStrategy":"validation","validationCode":"def norm_acks(v):\n    return int(v) if str(v).isdigit() else v\nacks = norm_acks(os.environ.get('KAFKA_ACKS', '1'))\nassert acks in (0, 1, 'all')\ncfg = MultiRegionKafkaProducerConfig(clusters=clusters, acks=acks)","typeGuard":null,"tryCatchPattern":"try:\n    cfg = MultiRegionKafkaProducerConfig(clusters=c, acks=a)\nexcept ValueError as e:\n    if 'acks' in str(e):\n        a = 'all'  # safe fallback\n        cfg = MultiRegionKafkaProducerConfig(clusters=c, acks=a)\n    else:\n        raise","preventionTips":["Whitelist acks values at the config-loading boundary","Never pass Java-style -1","Normalize env-var strings to int when numeric"],"tags":["kafka","producer","acks","pydantic","config-validation"],"backgroundTag":"invalid-config-value","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}