{"record":{"id":"736baf93862295d7","repo":"apache/beam","slug":"kwargs-were-specified-both-directly-and-as-a-row-object","errorCode":null,"errorMessage":"Kwargs were specified both directly and as a Row object","messagePattern":"Kwargs were specified both directly and as a Row object","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/PythonExternalTransform.java","lineNumber":200,"sourceCode":"  public PythonExternalTransform<InputT, OutputT> withArgs(@NonNull Object... args) {\n    @Nullable Object @NonNull [] result =\n        Arrays.copyOf(this.argsArray, this.argsArray.length + args.length);\n    System.arraycopy(args, 0, result, this.argsArray.length, args.length);\n    this.argsArray = result;\n    return this;\n  }\n\n  /**\n   * Specifies a single keyword argument for the Python cross-language transform. This may be\n   * invoked multiple times to add more than one keyword argument.\n   *\n   * @param name argument name.\n   * @param value argument value\n   * @return updated wrapper for the cross-language transform.\n   */\n  public PythonExternalTransform<InputT, OutputT> withKwarg(String name, Object value) {\n    if (providedKwargsRow != null) {\n      throw new IllegalArgumentException(\"Kwargs were specified both directly and as a Row object\");\n    }\n    kwargsMap.put(name, value);\n    return this;\n  }\n\n  /**\n   * Specifies keyword arguments for the Python cross-language transform. If invoked more than once,\n   * new keyword arguments map will be added to the previously prided keyword arguments.\n   *\n   * @return updated wrapper for the cross-language transform.\n   */\n  public PythonExternalTransform<InputT, OutputT> withKwargs(Map<String, Object> kwargs) {\n    if (providedKwargsRow != null) {\n      throw new IllegalArgumentException(\"Kwargs were specified both directly and as a Row object\");\n    }\n    kwargsMap.putAll(kwargs);\n    return this;\n  }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/PythonExternalTransform.java#L182-L218","documentation":"PythonExternalTransform lets you supply Python keyword arguments either as individual withKwarg(name, value) calls (accumulated in kwargsMap) or as a single Beam Row via withKwargs(Row). Once a Row was provided, adding an individual kwarg would be ambiguous about ordering/precedence, so withKwarg throws IllegalArgumentException.","triggerScenarios":"Calling .withKwargs(row) and then .withKwarg(name, value) on the same PythonExternalTransform builder.","commonSituations":"Adding one extra argument to an existing transform configuration that was already built from a Row; composing wrapper helpers where one path uses Row-based kwargs and another appends individual kwargs.","solutions":["Pass all arguments through one mechanism: add the extra field to the Row before calling withKwargs.","Use only withKwarg calls for every argument and drop the Row-based withKwargs call.","Rebuild the transform: if you need both, convert the Row's fields into withKwarg calls instead (withKwargs(Row) must be the only source)."],"exampleFix":"// before\ntransform.withKwargs(row).withKwarg(\"extra\", 1); // IllegalArgumentException\n// after\nRow newRow = Row.withSchema(row.getSchema()).addValues(row.getValues()).addValue(1).build();\ntransform.withKwargs(newRow);","handlingStrategy":"validation","validationCode":"// Java: only allow withKwarg when no Row was provided\nif (transformProvidedKwargsRow) {\n  throw new IllegalStateException(\"Add the field to the Row instead of calling withKwarg\");\n}","typeGuard":null,"tryCatchPattern":"try { return transform.withKwargs(row); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"both directly and as a Row\")) { /* unify kwargs into a single representation */ } else throw e; }","preventionTips":["Pick one kwarg style (Row or withKwarg) per transform and stick to it across helpers.","When extra args arrive late, merge them into the Row before withKwargs rather than appending after.","Wrap builder composition in a helper that enforces a single kwargs representation."],"tags":["java","cross-language","kwargs","builder-conflict"],"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-20T03:17:13.778Z"}