Skip to content

tango.pyaml.attribute.Attribute missing from accelerator.schema.json #445

Description

@GamelinAl

Summary

The published schemas/accelerator.schema.json has no branch for tango.pyaml.attribute.Attribute, the writable Tango attribute used by every setpoint of a static catalog. A configuration using it fails schema validation with "is not valid under any of the given schemas", although pyAML loads it fine.

Cause

SchemaGenerator (pyaml/validation/generator.py, model_schema, ~lines 210-239) replaces the schema of any class that has registered subclasses by a oneOf union of its subclasses only:

if not subclasses:
    return base_schema
subschemas = [self.generate_inner(item.__pydantic_core_schema__) for item in subclasses]
merged = {"oneOf": subschemas}          # base class itself is dropped

AttributeReadOnly subclasses Attribute, so Attribute is dropped from the union. The same happens to any concrete class that is also subclassed.

Reproduction

import json
s = json.load(open("schemas/accelerator.schema.json"))
consts = set()
def walk(o):
    if isinstance(o, dict):
        if "const" in o: consts.add(o["const"])
        for v in o.values(): walk(v)
    elif isinstance(o, list):
        for v in o: walk(v)
walk(s)
print("tango.pyaml.attribute.Attribute" in consts)                    # False
print("tango.pyaml.attribute_read_only.AttributeReadOnly" in consts)  # True

Expected

A concrete class that has subclasses should be kept in the union alongside its subclasses (i.e. oneOf: [base_schema, *subschemas] when the base class is itself instantiable/registered).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions