apache/beam · error · ValueError

Both deidentification_template_name and…

Error message

Both deidentification_template_name and deidentification_config were specified. Please specify only one of these.

What it means

CloudDLPOptions (cloud_dlp.py __init__) validates deidentification arguments as mutually exclusive: providing BOTH deidentification_template_name and deidentification_config is rejected because DLP should use either a stored template or an inline config, not both.

Solutions

  1. Pass only deidentification_template_name OR only deidentification_config
  2. If both sources set values, drop one before constructing CloudDLPOptions
  3. If a stored template should win, explicitly set the config argument to None

Example fix

// before
opts = CloudDLPOptions(project='p', inspection_config=cfg,
    deidentification_template_name=tmpl, deidentification_config=dcfg)

// after
opts = CloudDLPOptions(project='p', inspection_config=cfg,
    deidentification_template_name=tmpl)
Defensive patterns

Strategy: validation

Validate before calling

assert not (deid_template is not None and deid_config is not None), \
    'use either deidentification_template_name or deidentification_config, not both'

Try / catch

try:
    options = CloudDLPOptions(project=p, deidentification_template_name=t, deidentification_config=c, inspection_config=i)
except ValueError as e:
    if 'only one of these' in str(e):
        options = CloudDLPOptions(project=p, deidentification_template_name=t, inspection_config=i)

Prevention

When it happens

Trigger: Calling CloudDLPOptions(..., deidentification_template_name='projects/p/deidentifyTemplates/t', deidentification_config=DeidentifyConfig(...)) — both non-None.

Common situations: Merging config from two sources (defaults provide a template, user code adds an inline config); copy-paste adding both parameters; migrating from template to config while keeping the old argument.

Related errors


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

Appendix: source

Thrown at sdks/python/apache_beam/ml/gcp/cloud_dlp.py:96

        config is more important.
      inspection_template_name (str): This or `inspection_config` required.
        Name of inspection template to be used
        to detect sensitive data in text.
      inspection_config
        (``Union[dict, google.cloud.dlp_v2.types.InspectConfig]``):
        Configuration for the inspector used to detect sensitive data in text.
        If both template name and config are supplied,
        config takes precedence.
      timeout (float): Optional. The amount of time, in seconds, to wait for
        the request to complete.

    """
    self.config = {}
    self.project = project
    self.timeout = timeout
    if deidentification_template_name is not None \
        and deidentification_config is not None:
      raise ValueError(
          'Both deidentification_template_name and '
          'deidentification_config were specified.'
          ' Please specify only one of these.')
    elif deidentification_template_name is None \
        and deidentification_config is None:
      raise ValueError(
          'deidentification_template_name or '
          'deidentification_config must be specified.')
    elif deidentification_template_name is not None:
      self.config['deidentify_template_name'] = deidentification_template_name
    else:
      self.config['deidentify_config'] = deidentification_config

    if inspection_config is None and inspection_template_name is None:
      raise ValueError(
          'inspection_template_name or inspection_config must be specified')
    if inspection_template_name is not None:
      self.config['inspect_template_name'] = inspection_template_name

View on GitHub (pinned to 12126d8942)