Repository navigation
Remove artificial defaults from text nodes - #1240
Merged
Merged
Conversation
Generated str/bytes text fields no longer get default="". The parsers bind an empty value instead when the text is missing, but only for required str/bytes text fields without a default, so other fields keep their default or stay unset. Drop the unused default and tokens_factory params from ParserUtils.parse_var.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1240 +/- ##
=======================================
Coverage 99.97% 99.97%
=======================================
Files 117 117
Lines 9414 9421 +7
Branches 1447 1448 +1
=======================================
+ Hits 9412 9419 +7
Misses 1 1
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Oct 16, 2026
tefra
added a commit
to tefra/xsdata-w3c-tests
that referenced
this pull request
Oct 16, 2026
Generated text fields no longer get default="", so models drop the default and the pycode dumps write value='' explicitly. Depends on tefra/xsdata#1240
tefra
added a commit
to tefra/xsdata-samples
that referenced
this pull request
Oct 16, 2026
Generated text fields no longer get default="", so models drop the default and the pycode dumps write value='' explicitly. Depends on tefra/xsdata#1240
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



📒 Description
The generator used to give every str/bytes text field an artificial
default="". That produced odd models such as apatternrestriction whose default doesn't match the pattern:Text fields are now generated without a default, and the parsers bind the empty value instead. This replaces #1210, which made the same change in a single commit and had side effects in the parsers.
Breaking change: generated simple-content classes now need
valuepassed in, e.g.Comment()becomesComment(value="").🔗 What I've Done
ParserUtils.accepts_empty_text: missing text binds as""/b""only when the text field is required, has no default and is str/bytes. Every other field keeps its default or stays unset, as before.ElementNode.bind_textandDictDecoder.bind_dataclassuse that rule. The dict decoder writes to its params and leaves the input dict untouched.SanitizeAttributesDefaultValueno longer setsdefault=""on text nodes. The fixtures were regenerated.defaultandtokens_factoryparams fromParserUtils.parse_var.💬 Comments
Side effects of #1210 that this version avoids:
"";init=Falsetext is not validated against"";nulltext value in the dict decoder still falls back to the field default.Regression suites, run locally with dataclasses output:
default=""/default=b""lines, and the pycode dumps now writingvalue=''explicitly.🛫 Checklist