Spec check misses NewType arguments of a generic group

Aperta
#118 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@SimonHeybrock ci sta già lavorando.

Dal 28/10/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.

Lingua principale
Python
Stelle
0
Fork
1
Merge medio
15h 40m
PR unite (30g)
59

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scipp/essapps

Tutte le issue di scipp/essapps

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.