{"record":{"id":"226664c0e24c98d2","repo":"boto/boto3","slug":"either-a-boto3-client-or-s3transfer-manager-transf","errorCode":null,"errorMessage":"Either a boto3.Client or s3transfer.manager.TransferManager must be provided","messagePattern":"Either a boto3\\.Client or s3transfer\\.manager\\.TransferManager must be provided","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"boto3/s3/transfer.py","lineNumber":412,"sourceCode":"        resolved = {}\n        for init_arg, val in init_args.items():\n            if val is not None:\n                resolved[init_arg] = val\n            elif TRANSFER_CONFIG_SUPPORTS_CRT:\n                resolved[init_arg] = self.UNSET_DEFAULT\n            else:\n                resolved[init_arg] = self.DEFAULTS[init_arg]\n        return resolved\n\n\nclass S3Transfer:\n    ALLOWED_DOWNLOAD_ARGS = TransferManager.ALLOWED_DOWNLOAD_ARGS\n    ALLOWED_UPLOAD_ARGS = TransferManager.ALLOWED_UPLOAD_ARGS\n    ALLOWED_COPY_ARGS = TransferManager.ALLOWED_COPY_ARGS\n\n    def __init__(self, client=None, config=None, osutil=None, manager=None):\n        if not client and not manager:\n            raise ValueError(\n                'Either a boto3.Client or s3transfer.manager.TransferManager '\n                'must be provided'\n            )\n        if manager and any([client, config, osutil]):\n            raise ValueError(\n                'Manager cannot be provided with client, config, '\n                'nor osutil. These parameters are mutually exclusive.'\n            )\n        if config is None:\n            config = TransferConfig()\n        if osutil is None:\n            osutil = OSUtils()\n        if manager:\n            self._manager = manager\n        else:\n            self._manager = create_transfer_manager(client, config, osutil)\n\n    def upload_file(","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/boto/boto3/blob/6e10b029c1326a437932a8b24f38af69fd986e15/boto3/s3/transfer.py#L394-L430","documentation":"Raised by the `S3Transfer` constructor when neither `client` nor `manager` is supplied. `S3Transfer` needs either a low-level `boto3.client('s3')` to build its own internal manager, or a pre-built `s3transfer.manager.TransferManager`. Most users never instantiate `S3Transfer` directly because the convenience methods on `client`, `Bucket`, and `Object` already wire one up.","triggerScenarios":"Calling `S3Transfer()` with all-default arguments, or explicitly `S3Transfer(client=None, manager=None)`. Also when a variable intended to hold the client is None due to a failed/unevaluated client creation.","commonSituations":"Copy-pasting an example that constructs `S3Transfer` but forgetting to pass the client; refactoring code that previously passed `client=` and accidentally dropping it; the client creation failed earlier and the None propagated.","solutions":["Prefer the injected helpers (`client.upload_file`, `bucket.download_file`) — they construct S3Transfer correctly for you.","If you must build it, pass the client: `S3Transfer(client=s3_client)`.","Ensure the client is created before the transfer: `s3 = boto3.client('s3'); transfer = S3Transfer(client=s3)`.","Add an assert to catch None early: `assert s3_client is not None`."],"exampleFix":"# before\nfrom boto3.s3.transfer import S3Transfer\ntransfer = S3Transfer()  # ValueError: Either a boto3.Client or ... must be provided\n\n# after\nimport boto3\ntransfer = S3Transfer(client=boto3.client('s3'))\n\n# better: use the injected helper directly\nboto3.client('s3').upload_file('/tmp/f', 'bucket', 'key')","handlingStrategy":"validation","validationCode":"def make_transfer(client=None, manager=None):\n    assert client or manager, 'S3Transfer requires client or manager'\n    from boto3.s3.transfer import S3Transfer\n    return S3Transfer(client=client, manager=manager)","typeGuard":"def has_client_or_manager(client, manager) -> bool:\n    return bool(client) or bool(manager)","tryCatchPattern":"try:\n    transfer = S3Transfer(client=s3)\nexcept ValueError:\n    s3 = boto3.client('s3')\n    transfer = S3Transfer(client=s3)","preventionTips":["Prefer the injected helpers (client.upload_file/download_file) over constructing S3Transfer.","Create the S3 client in one place and reuse it.","Assert the client is not None before building a transfer."],"tags":["s3","transfer","constructor","argument-validation"],"backgroundTag":null,"analyzedSha":"6e10b029c1326a437932a8b24f38af69fd986e15","analyzedAt":"2026-08-11T20:52:47.213Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}