{"record":{"id":"73973746e47dac69","repo":"apache/beam","slug":"s-the-result-is-expected-to-be-an-integer-not-none","errorCode":null,"errorMessage":"%s: the result is expected to be an integer, not None.","messagePattern":"(.+?): the result is expected to be an integer, not None\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/testing/load_tests/load_test_metrics_utils.py","lineNumber":392,"sourceCode":"class DistributionMetric(Metric):\n  \"\"\"The Distribution Metric in ready-to-publish format.\n\n  Args:\n    dist_metric (object): distribution metric object from MetricResult\n    submit_timestamp (float): date-time of saving metric to database\n    metric_id (uuid): unique id to identify test run\n  \"\"\"\n  def __init__(self, dist_metric, submit_timestamp, metric_id, metric_type):\n    custom_label = dist_metric.key.metric.namespace + \\\n                   '_' + parse_step(dist_metric.key.step) + \\\n                   '_' + metric_type + \\\n                   '_' + dist_metric.key.metric.name\n    value = getattr(dist_metric.result, metric_type)\n    if value is None:\n      msg = '%s: the result is expected to be an integer, ' \\\n            'not None.' % custom_label\n      _LOGGER.debug(msg)\n      raise ValueError(msg)\n    super() \\\n      .__init__(submit_timestamp, metric_id, value, dist_metric, custom_label)\n\n\nclass RuntimeMetric(Metric):\n  \"\"\"The Distribution Metric in ready-to-publish format.\n\n  Args:\n    runtime_list: list of distributions metrics from MetricResult\n      with runtime name\n    metric_id(uuid): unique id to identify test run\n  \"\"\"\n  def __init__(self, runtime_list, metric_id):\n    value = self._prepare_runtime_metrics(runtime_list)\n    submit_timestamp = time.time()\n    # Label does not include step name, because it is one value calculated\n    # out of many steps\n    label = runtime_list[0].key.metric.namespace + \\","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/testing/load_tests/load_test_metrics_utils.py#L374-L410","documentation":"DistributionMetric.__init__ extracts a numeric field (e.g. mean, sum, min, max, count) from a distribution metric result and passes it to the base Metric. If that field is None — the runner did not report the requested statistic — it raises ValueError since the resulting metric value must be an integer.","triggerScenarios":"Constructing a DistributionMetric with a metric_type for which the runner's DistributionResult has no value (None), e.g. requesting a statistic not populated by the runner, or on a distribution that never received updates.","commonSituations":"Load-test metric extraction after a pipeline run where the distribution had zero updates; requesting an unsupported/absent metric_type from the distribution result; runners that report incomplete distribution results.","solutions":["Check the distribution result field for None before constructing the DistributionMetric and skip it","Ensure the metric was actually updated in the pipeline (distributions with no recorded values report None fields)","Use a metric_type guaranteed by the runner (e.g. 'sum' or 'count') instead of one that may be absent"],"exampleFix":"# before\nvalue = getattr(dist_metric.result, metric_type)\nmetric = DistributionMetric(submit_timestamp, dist_metric, metric_type, custom_label)  # raises if None\n# after\nvalue = getattr(dist_metric.result, metric_type)\nif value is not None:\n  metric = DistributionMetric(submit_timestamp, dist_metric, metric_type, custom_label)\nelse:\n  _LOGGER.warning('Skipping %s: no value reported', metric_type)","handlingStrategy":"try-catch","validationCode":"value = getattr(dist_metric.result, metric_type, None)\nif value is None:\n    logging.warning('Skipping %s: runner reported no value', metric_type)\n    return None  # skip constructing DistributionMetric","typeGuard":null,"tryCatchPattern":"try:\n    metric = DistributionMetric(submit_timestamp, dist_metric, metric_type, custom_label)\nexcept ValueError as e:\n    if 'expected to be an integer' in str(e):\n        logging.debug('No value for %s; skipping metric', metric_type)\n        metric = None\n    else:\n        raise","preventionTips":["Verify the distribution was actually updated in the pipeline before extracting stats","Only request statistic fields (mean/sum/min/max/count) that the runner populates","Guard extraction with a None check on getattr(result, metric_type)"],"tags":["python","apache-beam","metrics","distribution","load-testing"],"backgroundTag":"null-argument","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"}