Skip to content

fix: compare union defaults with dataclasses.MISSING (Python 3.15) - #984

Merged
marcosschroh merged 1 commit into
marcosschroh:masterfrom
cristianchiriac:fix-python-315-missing-type
Oct 17, 2026
Merged

marcosschroh merged 1 commit into
marcosschroh:masterfrom
cristianchiriac:fix-python-315-missing-type

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

Closes #983

UnionField.generate_unions_type checked type(self.default) is not dataclasses._MISSING_TYPE. Python 3.15 made dataclasses.MISSING a PEP 661 sentinel and removed the private _MISSING_TYPE class, so generating the schema of any union field raised AttributeError (the issue's traceback).

The check is now self.default is not dataclasses.MISSING. MISSING is a singleton on all supported versions, and the rest of the package (including the if right above this line) already compares with it this way.

Tested with poetry install --extras "pydantic faust faker" + pytest tests, in Docker:

before after
python:3.14 2964 passed
python:3.15 197 failed, 2767 passed 35 failed, 2929 passed

The issue's reproducer prints {"type": "record", "name": "Class", "fields": [{"name": "field", "type": ["string", "long"]}]} on 3.15.

The 35 remaining 3.15 failures are all in the faust tests and come from a dependency: mode/utils/objects.py calls typing._eval_type() without the type_params argument that 3.15 now requires. Nothing in this repo is involved, so I left those alone and didn't add 3.15 to the CI matrix.

dataclasses._MISSING_TYPE is still used in three return annotations (fields.py lines 200, 282, 571). Those don't run at runtime on 3.14+ (annotations are lazy), and typeshed still declares the class, so I didn't change them here.

Python 3.15 removed dataclasses._MISSING_TYPE, so generating the schema of
any union field failed with AttributeError. Closes #983
@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.76%. Comparing base (830d6bd) to head (9c8c8e8).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #984      +/-   ##
==========================================
+ Coverage   98.72%   98.76%   +0.04%     
==========================================
  Files          32       32              
  Lines        2271     2271              
==========================================
+ Hits         2242     2243       +1     
+ Misses         29       28       -1     

☔ View full report in Codecov by Harness.
📢 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.

@marcosschroh
marcosschroh merged commit 4eeed27 into marcosschroh:master Oct 17, 2026
9 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnionField.generate_unions_type fails in Python 3.15

2 participants