Skip to content

Replace discriminated unions with simple unions in models#385

Open
candleindark wants to merge 1 commit intomasterfrom
remove-discriminated-unions
Open

Replace discriminated unions with simple unions in models#385
candleindark wants to merge 1 commit intomasterfrom
remove-discriminated-unions

Conversation

@candleindark
Copy link
Copy Markdown
Member

Summary

Removes the use of discriminated unions in favor of plain Union[...] for the wasAssociatedWith, contributor, and about fields.

This has no effect on validation correctness: each union member has a distinct schemaKey: Literal[...] value, so Pydantic's smart union mode resolves the correct type without a discriminator.

The primary motivation is to enable translation to LinkML via pydantic2linkml, since LinkML has no comparable feature to discriminated unions (see dandi/pydantic2linkml#39).

Test plan

  • All existing tests pass (240 passed, 3 skipped)

🤖 Generated with Claude Code

Removes the use of discriminated unions in favor of plain `Union[...]` for
the `wasAssociatedWith`, `contributor`, and `about` fields. This has no
effect on validation correctness since each union member has a distinct
`schemaKey: Literal[...]` value, allowing Pydantic's smart union mode to
resolve the correct type. It also enables translation to LinkML via
pydantic2linkml since LinkML has no comparable feature to discriminated
unions (dandi/pydantic2linkml#39).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@yarikoptic
Copy link
Copy Markdown
Member

yarikoptic commented Mar 20, 2026

I would like to see the effect on schema.

DONE -- the diff: see/show the diff on jsonschema! I am surprised that our workflow didn't run at all -- we might want it to still run to visualize the diff, and then do its decision making on either to fail or not.... I will add release label just for that for now. We might want just to make it still run although not do categories

image

TODO: add to PR description analysis of why we had them to start with and analysis on possible effects on meditor

@yarikoptic yarikoptic added patch Increment the patch version when merged release Create a release when this pr is merged and removed release Create a release when this pr is merged labels Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Increment the patch version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants