{"record":{"id":"4d87155a38493754","repo":"apache/beam","slug":"expected-gaugedata-metric-type-but-received-s-with-value-s","errorCode":null,"errorMessage":"'Expected GaugeData metric type but received %s with value %s' % (type(metric), metric)","messagePattern":"'Expected GaugeData metric type but received (.+?) with value (.+?)' % \\(type\\(metric\\), metric\\)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/metrics/monitoring_infos.py","lineNumber":298,"sourceCode":"\n\ndef int64_user_gauge(\n    namespace, name, metric, ptransform=None) -> metrics_pb2.MonitoringInfo:\n  \"\"\"Return the gauge monitoring info for the URN, metric and labels.\n\n  Args:\n    namespace: User-defined namespace of gauge metric.\n    name: Name of gauge metric.\n    metric: The GaugeData containing the metrics.\n    ptransform: The ptransform id used as a label.\n  \"\"\"\n  labels = create_labels(ptransform=ptransform, namespace=namespace, name=name)\n  if isinstance(metric, GaugeData):\n    coder = coders.VarIntCoder()\n    value = metric.value\n    timestamp = metric.timestamp\n  else:\n    raise TypeError(\n        'Expected GaugeData metric type but received %s with value %s' %\n        (type(metric), metric))\n  payload = _encode_gauge(coder, timestamp, value)\n  return create_monitoring_info(\n      USER_GAUGE_URN, LATEST_INT64_TYPE, payload, labels)\n\n\ndef int64_gauge(urn, metric, ptransform=None) -> metrics_pb2.MonitoringInfo:\n  \"\"\"Return the gauge monitoring info for the URN, metric and labels.\n\n  Args:\n    urn: The URN of the monitoring info/metric.\n    metric: An int representing the value. The current time will be used for\n            the timestamp.\n    ptransform: The ptransform id used as a label.\n  \"\"\"\n  labels = create_labels(ptransform=ptransform)\n  if isinstance(metric, int):","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/metrics/monitoring_infos.py#L280-L316","documentation":"int64_user_gauge builds a user gauge MonitoringInfo and requires the metric to be a GaugeData instance carrying both value and timestamp. Passing any other object raises TypeError so a bare number or wrong type is never silently encoded as a gauge. This is a fail-fast input-type check during metric construction.","triggerScenarios":"Calling int64_user_gauge with an int, float, string, or None instead of a GaugeData instance, e.g. int64_user_gauge(ptransform=..., namespace=..., name=..., metric=42).","commonSituations":"Confusing int64_user_gauge (expects GaugeData) with int64_gauge (expects int); copying code between the two gauge builders; wrapping raw metric values read from another pipeline component.","solutions":["Wrap the value in GaugeData before calling: metric=GaugeData(value, timestamp=...).","If you have a plain int, call int64_gauge instead, which accepts ints.","Add an isinstance(metric, GaugeData) check before the call with a clear app-level error."],"exampleFix":"// before\nmi = int64_user_gauge(ptransform=pt, namespace='ns', name='latency', metric=42)\n// after\nfrom apache_beam.metrics.execution import GaugeData\nmi = int64_user_gauge(ptransform=pt, namespace='ns', name='latency', metric=GaugeData(42))","handlingStrategy":"type-guard","validationCode":"from apache_beam.metrics.execution import GaugeData\nif not isinstance(metric, GaugeData):\n    metric = GaugeData(metric)","typeGuard":"def is_gauge_data(m):\n    return isinstance(m, GaugeData)","tryCatchPattern":"try:\n    mi = int64_user_gauge(ptransform=pt, namespace=ns, name=name, metric=metric)\nexcept TypeError as e:\n    logger.error('user gauge requires GaugeData: %s', e)\n    raise","preventionTips":["Remember: int64_user_gauge takes GaugeData; int64_gauge takes int.","Construct GaugeData(value, timestamp=...) explicitly when you have raw numbers.","Add isinstance checks at call sites shared by both gauge APIs."],"tags":["python","apache-beam","metrics","type-mismatch","gauge"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}