{"record":{"id":"55a98dda3209a95a","repo":"apache/beam","slug":"unknown-namespace-type","errorCode":null,"errorMessage":"Unknown namespace type","messagePattern":"Unknown namespace type","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/metrics/metric.py","lineNumber":70,"sourceCode":"  from apache_beam.metrics.execution import MetricKey\n  from apache_beam.metrics.metricbase import Metric\n  from apache_beam.utils.histogram import BucketType\n\n__all__ = ['Metrics', 'MetricsFilter', 'Lineage']\n\n_LOGGER = logging.getLogger(__name__)\n\n\nclass Metrics(object):\n  \"\"\"Lets users create/access metric objects during pipeline execution.\"\"\"\n  @staticmethod\n  def get_namespace(namespace: Union[type, str]) -> str:\n    if isinstance(namespace, type):\n      return '{}.{}'.format(namespace.__module__, namespace.__name__)\n    elif isinstance(namespace, str):\n      return namespace\n    else:\n      raise ValueError('Unknown namespace type')\n\n  @staticmethod\n  def counter(\n      namespace: Union[type, str], name: str) -> 'Metrics.DelegatingCounter':\n    \"\"\"Obtains or creates a Counter metric.\n\n    Args:\n      namespace: A class or string that gives the namespace to a metric\n      name: A string that gives a unique name to a metric\n\n    Returns:\n      A Counter object.\n    \"\"\"\n    namespace = Metrics.get_namespace(namespace)\n    return Metrics.DelegatingCounter(MetricName(namespace, name))\n\n  @staticmethod\n  def distribution(","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/metrics/metric.py#L52-L88","documentation":"Metrics.get_namespace normalizes a namespace given as either a class or a plain string; the argument's type is neither, so no namespace string can be derived. This is a type guard on the namespace parameter of metric creation/filtering.","triggerScenarios":"Passing an object instance instead of a class (e.g. Metrics.counter(my_obj, 'name')), None, or a non-str type like bytes or int as the namespace argument to Metrics.counter/gauge/distribution.","commonSituations":"Accidentally passing a class instance (self) rather than the class (self.__class__); passing an enum member or variable holding an unexpected type from config.","solutions":["Pass the class itself (MyClass) not an instance, or pass a plain string namespace.","If you have an instance, use type(instance) or instance.__class__ as the namespace.","Coerce other values to str before passing."],"exampleFix":"- Metrics.counter(self, 'items')\n+ Metrics.counter(type(self), 'items')\n# or\n+ Metrics.counter('mynamespace', 'items')","handlingStrategy":"type-guard","validationCode":"assert isinstance(namespace, (str, type)), f'namespace must be str or class, got {type(namespace)}'","typeGuard":"def is_valid_namespace(ns):\n    return isinstance(ns, str) or isinstance(ns, type)","tryCatchPattern":"try:\n    ns = Metrics.get_namespace(namespace)\nexcept ValueError:\n    ns = str(namespace)","preventionTips":["Pass classes (not instances) or plain strings as namespaces.","Use type(obj) when you only have an instance.","Coerce config-derived namespace values to str early."],"tags":["python","apache-beam","metrics","type-error"],"backgroundTag":"invalid-argument-value","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"}