{"record":{"id":"5a69748f5b408ee0","repo":"apache/beam","slug":"either-size-or-error-should-be-set-received","errorCode":null,"errorMessage":"Either size or error should be set. Received {}.","messagePattern":"Either size or error should be set\\. Received (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/stats.py","lineNumber":124,"sourceCode":"  def parse_input_params(size=None, error=None):\n    \"\"\"\n    Check if input params are valid and return sample size.\n\n    :param size: an int not smaller than 16, which we would use to estimate\n      number of unique values.\n    :param error: max estimation error, which is a float between 0.01 and 0.50.\n      If error is given, sample size will be calculated from error with\n      _get_sample_size_from_est_error function.\n    :return: sample size\n    :raises:\n      ValueError: If both size and error are given, or neither is given, or\n      values are out of range.\n    \"\"\"\n\n    if None not in (size, error):\n      raise ValueError(ApproximateUnique._MULTI_VALUE_ERR_MSG % (size, error))\n    elif size is None and error is None:\n      raise ValueError(ApproximateUnique._NO_VALUE_ERR_MSG)\n    elif size is not None:\n      if not isinstance(size, int) or size < 16:\n        raise ValueError(ApproximateUnique._INPUT_SIZE_ERR_MSG % (size))\n      else:\n        return size\n    else:\n      if error < 0.01 or error > 0.5:\n        raise ValueError(ApproximateUnique._INPUT_ERROR_ERR_MSG % (error))\n      else:\n        return ApproximateUnique._get_sample_size_from_est_error(error)\n\n  @staticmethod\n  def _get_sample_size_from_est_error(est_err):\n    \"\"\"\n    :return: sample size\n\n    Calculate sample size from estimation error\n    \"\"\"","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/stats.py#L106-L142","documentation":"The same mutual-exclusion rule as 3836: parse_input_params raises ApproximateUnique._NO_VALUE_ERR_MSG ('Either size or error should be set. Received {}.') when NEITHER size nor error is provided. At least one parameter must be present to define the estimator.","triggerScenarios":"beam.ApproximateUnique() with no arguments; a config/transform spec where the key holding size/error was renamed or dropped so the value arrives as None.","commonSituations":"Dynamic configuration where the field name changed (e.g. 'sample_size' vs 'size'), leaving both unset; template fills missing optional parameters.","solutions":["Pass exactly one of size or error to ApproximateUnique.","Validate configuration before building the pipeline so missing fields fail early with a clear message.","Default one parameter explicitly in your wrapper, e.g. error=0.02."],"exampleFix":"// before\nbeam.ApproximateUnique()\n// after\nbeam.ApproximateUnique(error=0.02)","handlingStrategy":"validation","validationCode":"assert size is not None or error is not None, \\\n    'ApproximateUnique requires size or error'\nif size is None and error is None:\n    error = 0.02  # default","typeGuard":"def has_estimation_param(size, error) -> bool:\n    return size is not None or error is not None","tryCatchPattern":"try:\n    t = beam.ApproximateUnique(size=size, error=error)\nexcept ValueError as e:\n    if 'Either size or error' in str(e):\n        t = beam.ApproximateUnique(error=0.02)  # sensible default\n    else:\n        raise","preventionTips":["Always pass an explicit error or size to ApproximateUnique.","Use keyword arguments so renamed config keys fail validation, not silently arrive as None.","Default the parameter in your pipeline template schema."],"tags":["python","apache-beam","approximateunique","missing-parameter"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}