apache/beam · error · IllegalArgumentException

Extra packages were already specified

Error message

Extra packages were already specified

What it means

This IllegalArgumentException is thrown by RunInference.withExtraPackages when extra PyPi packages were already specified on this RunInference instance. The library allows packages to be set at most once so the model-runner configuration stays deterministic. A second call would silently alter already-configured state, so it is rejected.

Source

Thrown at sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/transforms/RunInference.java:146

  }

  /**
   * Specifies any extra packages required by the RunInference model handler.
   *
   * <p>This should only be specified when using the default expansion service, i.e. when not using
   * {@link #withExpansionService(String)} to provide an expansion service.
   *
   * <p>The package can either be a PyPi package or the path to a locally available Python package.
   *
   * <p>For model handlers provided by Beam Python SDK, the implementation will automatically try to
   * infer correct packages needed, so this may be omitted.
   *
   * @param extraPackages a list of PyPi packages. May include the version.
   * @return A {@link RunInference} with extra packages.
   */
  public RunInference<OutputT> withExtraPackages(List<String> extraPackages) {
    if (!this.extraPackages.isEmpty()) {
      throw new IllegalArgumentException("Extra packages were already specified");
    }
    this.extraPackages.addAll(extraPackages);
    return this;
  }

  /**
   * Sets an expansion service endpoint for RunInference.
   *
   * @param expansionService A URL for a Python expansion service.
   * @return A {@link RunInference} for the given expansion service endpoint.
   */
  public RunInference<OutputT> withExpansionService(String expansionService) {
    return new RunInference<>(modelLoader, schema, kwargs, keyCoder, expansionService);
  }

  private RunInference(
      String modelLoader,
      Schema schema,

View on GitHub (pinned to 12126d8942)

Solutions

  1. Aggregate all required packages into a single List and call withExtraPackages once.
  2. Merge package lists from different config sources before invoking the method.
  3. Construct a new RunInference instance if a different package set is needed.
  4. Audit pipeline code for duplicate fluent calls to withExtraPackages.

Example fix

// before
runInference.withExtraPackages(List.of("numpy")).withExtraPackages(List.of("scipy"));
// after
runInference.withExtraPackages(List.of("numpy", "scipy"));
Defensive patterns

Strategy: validation

Validate before calling

if (extraPackages == null || extraPackages.isEmpty()) {
  runInference = runInference.withExtraPackages(allPkgs);
}

Try / catch

try {
  runInference = runInference.withExtraPackages(pkgs);
} catch (IllegalArgumentException e) {
  // already specified; ignore or create a new RunInference instance
}

Prevention

When it happens

Trigger: Calling withExtraPackages(...) twice on the same RunInference instance, e.g. runInference.withExtraPackages(a).withExtraPackages(b), after extraPackages has already been populated.

Common situations: Composing model-runner configuration from defaults plus user overrides where both call withExtraPackages; fluent chain duplication; framework code that re-applies settings.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/f9bfec5e3e3c8c47. Report an issue: GitHub.