apache/beam · error · Error
Keyword arguments cannot be specified twice.
Error message
Keyword arguments cannot be specified twice.
What it means
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.
Source
Thrown at sdks/typescript/src/apache_beam/transforms/python.ts:60
* See also https://beam.apache.org/documentation/programming-guide/#1324-using-cross-language-transforms-in-a-typescript-pipeline
*/
export function pythonTransform<
InputT extends beam.PValue<any>,
OutputT extends beam.PValue<any>,
>(
constructor: string,
args_or_kwargs: any[] | { [key: string]: any } | undefined = undefined,
kwargs: { [key: string]: any } | undefined = undefined,
options: external.RawExternalTransformOptions = {},
): beam.AsyncPTransform<InputT, OutputT> {
let args;
if (args_or_kwargs === undefined) {
args = [];
} else if (Array.isArray(args_or_kwargs)) {
args = args_or_kwargs;
} else {
if (kwargs != undefined) {
throw new Error("Keyword arguments cannot be specified twice.");
}
args = [];
kwargs = args_or_kwargs;
}
if (kwargs === undefined) {
kwargs = {};
}
return external.rawExternalTransform<InputT, OutputT>(
"beam:transforms:python:fully_qualified_named",
{
constructor: constructor,
args: Object.fromEntries(args.map((arg, ix) => ["arg" + ix, arg])),
kwargs,
},
// "localhost:4444"
async () =>View on GitHub (pinned to 12126d8942)
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.
Example fix
// before
pythonTransform('ReadFromText', {pattern: 'f*'}, {compression_type: 'gzip'});
// after
pythonTransform('ReadFromText', {pattern: 'f*', compression_type: 'gzip'}); Defensive patterns
Strategy: validation
Validate before calling
function checkNoDupKwargs(argsOrKwargs, kwargs) {
if (argsOrKwargs !== undefined && !Array.isArray(argsOrKwargs) && kwargs !== undefined)
throw new TypeError('Pass args array OR kwargs object, not both');
} Type guard
const isKwargsObj = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Copy-pasting a call and adding a second kwargs object; misunderstanding that the object form of the second argument replaces the kwargs parameter.
Related errors
- Method %s should not have return type RuntimeValueProvider,
- Method %s should not have return type StaticValueProvider, u
- Specified path '%s' already used for subcomponent %s. Subcom
- IllegalArgumentException
- String.valueOf(errorMessage)
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/5ff8046007f899f6.
Report an issue: GitHub.