Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xsd:string text nodes should have empty string as default value #570

Merged
merged 6 commits into from
Jul 30, 2021

Conversation

tefra
Copy link
Owner

@tefra tefra commented Jul 28, 2021

Early on I made the decision to treat empty values as None for text nodes, which is not correct, xml parsers obviously don't know about the schema but xsdata can make the distinction between empty content and nil content.

  • Make text nodes required unless are marked explicitly nillable
  • Separate bindings for nillable types and nillable elements (nillable elements are None, nillable types are objects with None text values)
  • Cascade xs:element default/fixed/nillable properties only to text nodes
  • Explicitly mark as optional nillable nodes even if they have a default value
  • Set default value to empty string for str text nodes if not set (wip)
  • ElementMapper should handle xsi:nil attributes as well

todos

  • I am still debating if this should be a feature that can be enabled/disabled. I am thinking default On / Strict
  • I still have some failures in w3c test suite regarding text nodes derived from xs:any, xs:anySimpleType, ... and kw_only dataclasses

Resolves hopefully #567

@tefra tefra added the wip label Jul 28, 2021
@codecov
Copy link

codecov bot commented Jul 28, 2021

Codecov Report

Merging #570 (14b96a6) into master (56e885e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #570   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           93        93           
  Lines         7965      7983   +18     
  Branches      1368      1373    +5     
=========================================
+ Hits          7965      7983   +18     
Impacted Files Coverage Δ
xsdata/utils/testing.py 100.00% <ø> (ø)
xsdata/codegen/container.py 100.00% <100.00%> (ø)
xsdata/codegen/handlers/__init__.py 100.00% <100.00%> (ø)
xsdata/codegen/handlers/attribute_default_value.py 100.00% <100.00%> (ø)
xsdata/codegen/handlers/attribute_normalize.py 100.00% <100.00%> (ø)
xsdata/codegen/handlers/class_extension.py 100.00% <100.00%> (ø)
xsdata/codegen/mappers/element.py 100.00% <100.00%> (ø)
xsdata/codegen/models.py 100.00% <100.00%> (ø)
xsdata/formats/dataclass/filters.py 100.00% <100.00%> (ø)
xsdata/formats/dataclass/parsers/bases.py 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56e885e...14b96a6. Read the comment docs.

@tefra tefra force-pushed the feat-567 branch 2 times, most recently from b93411c to bd4c1c1 Compare July 29, 2021 18:52
tefra added 3 commits July 29, 2021 22:02
- Nillable fields can be initialized with None
- Fields with nillable types can be initialized with nil content
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@tefra tefra merged commit e847fcb into master Jul 30, 2021
@tefra tefra deleted the feat-567 branch July 30, 2021 19:36
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.

1 participant