apache/beam · error · ValueError

cannot specify "expression" or "callable" with "path" or…

Error message

{transform_name} cannot specify "expression" or "callable" with "path" or "name"

What it means

_check_mapping_arguments disallows combining inline definitions (expression or callable) with external loading options (path or name). This ValueError fires when any of expression/callable is set together with path or name, since a field must be defined either inline or externally, not both.

Solutions

  1. Delete the inline `expression`/`callable` and keep path+name for external loading.
  2. Or delete `path`/`name` and keep the inline definition.
  3. Keep each field's definition in exactly one style.
  4. Review copied YAML templates for leftover keys.

Example fix

# before
config:
  expression: "x + 1"
  path: ./myfuncs.py
  name: double
# after
config:
  path: ./myfuncs.py
  name: double
Defensive patterns

Strategy: validation

Validate before calling

inline = bool(config.get('expression') or config.get('callable'))
external = bool(config.get('path') or config.get('name'))
assert not (inline and external), 'cannot mix inline and path/name definitions'

Prevention

When it happens

Trigger: Configuring a mapping transform where `expression` (or `callable`) coexists with `path` and/or `name` in the same configuration.

Common situations: Adding an import path for a helper while leaving a stale inline expression; template configs that already contain one style plus a newly pasted other style.

Related errors


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

Appendix: source

Thrown at sdks/python/apache_beam/yaml/yaml_mapping.py:174

  elif base_type in _str_expression_fields:
    param = _str_expression_fields[base_type]
    validate_generic_expression(
        config.get(param), input_fields, base_type == 'Filter', param)


def _check_mapping_arguments(
    transform_name, expression=None, callable=None, name=None, path=None):
  # Argument checking
  if not expression and not callable and not path and not name:
    raise ValueError(
        f'{transform_name} must specify either "expression", "callable", '
        f'or both "path" and "name"')
  if expression and callable:
    raise ValueError(
        f'{transform_name} cannot specify both "expression" and "callable"')
  if (expression or callable) and (path or name):
    raise ValueError(
        f'{transform_name} cannot specify "expression" or "callable" with '
        f'"path" or "name"')
  if path and not name:
    raise ValueError(f'{transform_name} cannot specify "path" without "name"')
  if name and not path:
    raise ValueError(f'{transform_name} cannot specify "name" without "path"')


_THREAD_LOCAL_JS_CACHE = threading.local()


class _JsFunctionWrapper:
  def __init__(self, source_code, entrypoint_name):
    self.source_code = source_code
    self.entrypoint_name = entrypoint_name

  def _get_fn(self):
    cache = _THREAD_LOCAL_JS_CACHE

View on GitHub (pinned to 12126d8942)