{"record":{"id":"f9bfec5e3e3c8c47","repo":"apache/beam","slug":"extra-packages-were-already-specified-runinference","errorCode":null,"errorMessage":"Extra packages were already specified","messagePattern":"Extra packages were already specified","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/transforms/RunInference.java","lineNumber":146,"sourceCode":"  }\n\n  /**\n   * Specifies any extra packages required by the RunInference model handler.\n   *\n   * <p>This should only be specified when using the default expansion service, i.e. when not using\n   * {@link #withExpansionService(String)} to provide an expansion service.\n   *\n   * <p>The package can either be a PyPi package or the path to a locally available Python package.\n   *\n   * <p>For model handlers provided by Beam Python SDK, the implementation will automatically try to\n   * infer correct packages needed, so this may be omitted.\n   *\n   * @param extraPackages a list of PyPi packages. May include the version.\n   * @return A {@link RunInference} with extra packages.\n   */\n  public RunInference<OutputT> withExtraPackages(List<String> extraPackages) {\n    if (!this.extraPackages.isEmpty()) {\n      throw new IllegalArgumentException(\"Extra packages were already specified\");\n    }\n    this.extraPackages.addAll(extraPackages);\n    return this;\n  }\n\n  /**\n   * Sets an expansion service endpoint for RunInference.\n   *\n   * @param expansionService A URL for a Python expansion service.\n   * @return A {@link RunInference} for the given expansion service endpoint.\n   */\n  public RunInference<OutputT> withExpansionService(String expansionService) {\n    return new RunInference<>(modelLoader, schema, kwargs, keyCoder, expansionService);\n  }\n\n  private RunInference(\n      String modelLoader,\n      Schema schema,","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/transforms/RunInference.java#L128-L164","documentation":"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.","triggerScenarios":"Calling withExtraPackages(...) twice on the same RunInference instance, e.g. runInference.withExtraPackages(a).withExtraPackages(b), after extraPackages has already been populated.","commonSituations":"Composing model-runner configuration from defaults plus user overrides where both call withExtraPackages; fluent chain duplication; framework code that re-applies settings.","solutions":["Aggregate all required packages into a single List and call withExtraPackages once.","Merge package lists from different config sources before invoking the method.","Construct a new RunInference instance if a different package set is needed.","Audit pipeline code for duplicate fluent calls to withExtraPackages."],"exampleFix":"// before\nrunInference.withExtraPackages(List.of(\"numpy\")).withExtraPackages(List.of(\"scipy\"));\n// after\nrunInference.withExtraPackages(List.of(\"numpy\", \"scipy\"));","handlingStrategy":"validation","validationCode":"if (extraPackages == null || extraPackages.isEmpty()) {\n  runInference = runInference.withExtraPackages(allPkgs);\n}","typeGuard":null,"tryCatchPattern":"try {\n  runInference = runInference.withExtraPackages(pkgs);\n} catch (IllegalArgumentException e) {\n  // already specified; ignore or create a new RunInference instance\n}","preventionTips":["Set extra packages once, with a fully merged list.","Do not chain multiple withExtraPackages calls.","Use a single configuration source for packages.","Document the single-call contract for pipeline authors."],"tags":["java","builder-pattern","illegal-argument","configuration"],"backgroundTag":"conflicting-config-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"}