Spec check misses NewType arguments of a generic group

Abierto
#118 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@SimonHeybrock ya está trabajando en esto.

Desde el 28/10/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

Summary

A spec may use a generic group parametrized with a NewType, such as essreduce's polarization markers. WorkflowSpec accepts it, but two such parameters serialize as one type, so a consumer of the serialized spec cannot tell them apart. It has the same root cause as scipp/sciline#250: pydantic names a generic model after its arguments, and gives every NewType the name NewType.

Reproducer

Polarizer = NewType('Polarizer', str)   # as in ess.reduce.polarization.types
Analyzer = NewType('Analyzer', str)
E = TypeVar('E')

class He3Cell(BaseModel, Generic[E]):
    pressure: float = Field(1.0, gt=0)

class Params(BaseModel):
    polarizer: He3Cell[Polarizer]
    analyzer: He3Cell[Analyzer]

spec = WorkflowSpec(..., params=Params, ...)   # accepted
schema = spec.serialize().params_schema
list(schema['$defs'])                          # [..., 'He3Cell_NewType_', ...]: one entry for both
schema['properties']['polarizer']              # ... 'dataType': 'He3Cell[NewType]'
schema['properties']['analyzer']               # ... 'dataType': 'He3Cell[NewType]'

Impact

Inside one process nothing goes wrong. The backend fits a reference by class identity (field_types.fits), and a PipelineBinding uses the class objects as sciline keys. A consumer that only has the serialized spec, such as a remote UI, matches an output to a parameter by dataType. It would offer a polarizer cell's output for the analyzer, and the other way round. No such consumer exists yet.

Proposal

Refuse it when the spec is made, as the rule "no NewType or type alias, at any depth" already intends (essspec ADR 0001). The check misses this case because field_types.arguments uses typing.get_args, which does not see the arguments of a parametrized pydantic model. Those are in __pydantic_generic_metadata__['args']. With them included, the existing message applies: a spec names a role by a class.

The fix at the source is in essreduce: define the markers as classes (class Polarizer: ...). That also fixes scipp/sciline#250 for these keys. Until then, a spec over essreduce's He3 workflow defines its own marker classes, and its binding maps them to essreduce's keys.

Lenguaje dominante
Python
Estrellas
0
Forks
1
Merge medio
9 h 40 min
PR fusionados (30 d)
60

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de scipp/essapps

Todos los issues de scipp/essapps

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.