Skip to content

Replace discriminated unions with simple unions in models#385

Open
candleindark wants to merge 2 commits intomasterfrom
remove-discriminated-unions
Open

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

Conversation

@candleindark
Copy link
Copy Markdown
Member

@candleindark candleindark commented Mar 20, 2026

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).

Notes:
Use of discriminated unions was introduced to improve validation error messages per #244.

Test plan

  • All existing tests pass (240 passed, 3 skipped)
  • Analyze the effect of this change on meditor

🤖 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
@candleindark
Copy link
Copy Markdown
Member Author

Note: use of discriminated unions was introduced to improve validation error messages per #244.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.31%. Comparing base (9c694b5) to head (ce42f55).

Files with missing lines Patch % Lines
dandischema/models.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #385   +/-   ##
=======================================
  Coverage   48.31%   48.31%           
=======================================
  Files          19       19           
  Lines        2434     2434           
=======================================
  Hits         1176     1176           
  Misses       1258     1258           
Flag Coverage Δ
unittests 48.31% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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