{"record":{"id":"5ff8046007f899f6","repo":"apache/beam","slug":"keyword-arguments-cannot-be-specified-twice","errorCode":null,"errorMessage":"Keyword arguments cannot be specified twice.","messagePattern":"Keyword arguments cannot be specified twice\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"sdks/typescript/src/apache_beam/transforms/python.ts","lineNumber":60,"sourceCode":" * See also https://beam.apache.org/documentation/programming-guide/#1324-using-cross-language-transforms-in-a-typescript-pipeline\n */\nexport function pythonTransform<\n  InputT extends beam.PValue<any>,\n  OutputT extends beam.PValue<any>,\n>(\n  constructor: string,\n  args_or_kwargs: any[] | { [key: string]: any } | undefined = undefined,\n  kwargs: { [key: string]: any } | undefined = undefined,\n  options: external.RawExternalTransformOptions = {},\n): beam.AsyncPTransform<InputT, OutputT> {\n  let args;\n  if (args_or_kwargs === undefined) {\n    args = [];\n  } else if (Array.isArray(args_or_kwargs)) {\n    args = args_or_kwargs;\n  } else {\n    if (kwargs != undefined) {\n      throw new Error(\"Keyword arguments cannot be specified twice.\");\n    }\n    args = [];\n    kwargs = args_or_kwargs;\n  }\n\n  if (kwargs === undefined) {\n    kwargs = {};\n  }\n\n  return external.rawExternalTransform<InputT, OutputT>(\n    \"beam:transforms:python:fully_qualified_named\",\n    {\n      constructor: constructor,\n      args: Object.fromEntries(args.map((arg, ix) => [\"arg\" + ix, arg])),\n      kwargs,\n    },\n    //     \"localhost:4444\"\n    async () =>","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/typescript/src/apache_beam/transforms/python.ts#L42-L78","documentation":"pythonTransform accepts its configuration either as a positional args array OR as a kwargs object (with optional kwargs param), not both. When the first argument is a kwargs object (not an array) and a kwargs object was also passed in the second parameter, the library cannot merge them unambiguously and throws. This guards against silently duplicating keyword arguments passed to the underlying Python transform.","triggerScenarios":"Calling any wrapper such as `readFromText(filePattern, {compression_type: 'gzip'}, {compression_type: 'gzip'})` — i.e. passing a non-array object as args_or_kwargs while also passing kwargs.","commonSituations":"Copy-pasting a call and adding a second kwargs object; misunderstanding that the object form of the second argument replaces the kwargs parameter.","solutions":["Merge the two objects into one kwargs object and pass it as a single argument.","If positional args are needed, pass them as an array as the first parameter and keep kwargs separately.","Pass only one of the two arguments."],"exampleFix":"// before\npythonTransform('ReadFromText', {pattern: 'f*'}, {compression_type: 'gzip'});\n\n// after\npythonTransform('ReadFromText', {pattern: 'f*', compression_type: 'gzip'});","handlingStrategy":"validation","validationCode":"function checkNoDupKwargs(argsOrKwargs, kwargs) {\n  if (argsOrKwargs !== undefined && !Array.isArray(argsOrKwargs) && kwargs !== undefined)\n    throw new TypeError('Pass args array OR kwargs object, not both');\n}","typeGuard":"const isKwargsObj = (v: unknown): v is Record<string, unknown> =>\n  typeof v === 'object' && v !== null && !Array.isArray(v);","tryCatchPattern":null,"preventionTips":["Pick one style per call site: array args or a single kwargs object.","Merge config objects before passing them to pythonTransform wrappers.","Wrap common read/write helpers in thin functions with fixed signatures."],"tags":["arguments","python-interop","api-misuse"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}