{"record":{"id":"8672169e61ccd2f8","repo":"cocoindex-io/cocoindex","slug":"cannot-specify-both-an-s3-uri-and-a-separate-key","errorCode":null,"errorMessage":"Cannot specify both an S3 URI and a separate key. Pass either get_object(client, 's3://bucket/key') or get_object(client, 'bucket', 'key').","messagePattern":"Cannot specify both an S3 URI and a separate key\\. Pass either get_object\\(client, 's3://bucket/key'\\) or get_object\\(client, 'bucket', 'key'\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/amazon_s3/_source.py","lineNumber":218,"sourceCode":"\n    Example::\n\n        import aiobotocore.session\n        from cocoindex.connectors import amazon_s3\n\n        session = aiobotocore.session.get_session()\n        async with session.create_client(\"s3\") as client:\n            # Via S3 URI:\n            f = await amazon_s3.get_object(client, \"s3://my-bucket/data/config.json\")\n            data = await f.read()\n\n            # Via bucket name + key:\n            f = await amazon_s3.get_object(client, \"my-bucket\", \"data/config.json\")\n            data = await f.read()\n    \"\"\"\n    if bucket_name_or_uri.startswith(\"s3://\"):\n        if key is not None:\n            raise ValueError(\n                \"Cannot specify both an S3 URI and a separate key. \"\n                \"Pass either get_object(client, 's3://bucket/key') \"\n                \"or get_object(client, 'bucket', 'key').\"\n            )\n        bucket_name, key = _parse_s3_uri(bucket_name_or_uri)\n    else:\n        bucket_name = bucket_name_or_uri\n        if key is None:\n            raise ValueError(\n                \"key must be provided when bucket_name_or_uri is not an S3 URI.\"\n            )\n    return await _s3file_from_head(client, bucket_name, key)\n\n\nasync def read(client: AioBaseClient, uri: str, size: int = -1) -> bytes:\n    \"\"\"\n    Read object content directly from an S3 URI.\n","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/amazon_s3/_source.py#L200-L236","documentation":"get_object accepts either an S3 URI ('s3://bucket/key') or a separate bucket name plus key, but not both at once. Passing a URI as the first argument together with a key kwarg is ambiguous, so the function raises this ValueError.","triggerScenarios":"Calling `amazon_s3.get_object(client, 's3://my-bucket/data/config.json', 'data/config.json')` or `get_object(client, 's3://bucket/key', key='key')` — first arg starts with s3:// and key is not None.","commonSituations":"Refactoring code from the two-argument form to the URI form (or vice versa) and leaving the old key argument in place; copying example code and editing only one parameter.","solutions":["Remove the key argument and pass only the URI: get_object(client, 's3://bucket/key').","Or drop the s3:// prefix from the first argument and pass bucket and key separately: get_object(client, 'bucket', 'key').","If the first argument comes from config, normalize it: if it starts with 's3://', don't forward a key."],"exampleFix":"// before\nf = await amazon_s3.get_object(client, \"s3://my-bucket/data/config.json\", \"data/config.json\")\n\n// after\nf = await amazon_s3.get_object(client, \"s3://my-bucket/data/config.json\")","handlingStrategy":"validation","validationCode":"def get_object_once(client, bucket_or_uri, key=None):\n    if bucket_or_uri.startswith(\"s3://\") and key is not None:\n        raise ValueError(\"pass either URI or (bucket, key), not both\")\n    return amazon_s3.get_object(client, bucket_or_uri) if key is None else amazon_s3.get_object(client, bucket_or_uri, key)","typeGuard":null,"tryCatchPattern":"try:\n    f = await amazon_s3.get_object(client, uri, key)\nexcept ValueError as e:\n    # fall back to URI-only form\n    f = await amazon_s3.get_object(client, uri)","preventionTips":["Pick one calling convention per codebase and stick to it.","When refactoring between forms, grep call sites for leftover key arguments.","Wrap the API in a small helper that accepts a single object descriptor."],"tags":["python","s3","arguments","validation"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}