apache/beam · error · ValueError
Spec type not found in
Error message
Spec type not found in {spec} What it means
Specifiable.from_spec instantiates a Specifiable subclass from a Spec dataclass. If the Spec's .type field is None, the lookup cannot proceed and a ValueError is raised. This is a required-field check before resolving the type to a registered subclass.
Solutions
- Set Spec.type to a registered specifiable type string, e.g. Spec(type='ZScore', config=...).
- Validate the spec before calling from_spec: assert spec.type is not None.
- Fix the deserialization/config source so the 'type' field is included.
- Check the spec's repr in the error message to see which fields were actually populated.
Example fix
// before
spec = Spec(type=None, config={"threshold": 3})
// after
spec = Spec(type="ZScore", config={"threshold": 3}) Defensive patterns
Strategy: validation
Validate before calling
if spec.type is None:
raise ValueError(f"Spec.type required before from_spec: {spec}") Type guard
def has_type(spec): return getattr(spec, 'type', None) is not None
Try / catch
try:
obj = Specifiable.from_spec(spec)
except ValueError as e:
logger.error("incomplete spec: %s", e)
raise Prevention
- Always pass type explicitly to Spec()
- Validate deserialized spec dicts contain a 'type' key
- Avoid relying on dataclass defaults for required fields
When it happens
Trigger: Constructing a Spec() without passing type (e.g. Spec(config=...) or relying on the default None) and then passing it to from_spec; programmatically built specs where the type assignment was skipped.
Common situations: Specs deserialized from config/JSON missing the 'type' key; dataclass defaults leaving type unset; code paths that build a Spec incrementally and forget to set type.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- subspace for not found.
- Unknown spec type ' ' in
- "IQR.learn_one expected univariate input, but got
- "IQR.score_one expected univariate input, but got
- Missing required field
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/20f60af0f4a7e3b6.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/ml/anomaly/specifiable.py:169
@classmethod
def spec_type(cls) -> str:
pass
@classmethod
def from_spec(cls,
spec: Spec,
_run_init: bool = True) -> Union[Self, type[Self]]:
"""Generate a `Specifiable` subclass object based on a spec.
Args:
spec: the specification of a `Specifiable` subclass object
_run_init: whether to call `__init__` or not for the initial instantiation
Returns:
Self: the `Specifiable` subclass object
"""
if spec.type is None:
raise ValueError(f"Spec type not found in {spec}")
subspace = _spec_type_to_subspace(spec.type)
subclass: type[Self] = _KNOWN_SPECIFIABLE[subspace].get(spec.type, None)
if subclass is None:
raise ValueError(f"Unknown spec type '{spec.type}' in {spec}")
if spec.config is None:
# when functions or classes are used as arguments, we won't try to
# create an instance.
return subclass
kwargs = {
k: _specifiable_from_spec_helper(v, _run_init)
for k, v in spec.config.items()
}
if _run_init:View on GitHub (pinned to 12126d8942)