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

fix: Prohibited fields need default value None #1098

Merged
merged 1 commit into from
Dec 1, 2024
Merged

fix: Prohibited fields need default value None #1098

merged 1 commit into from
Dec 1, 2024

Conversation

tefra
Copy link
Owner

@tefra tefra commented Dec 1, 2024

📒 Description

Prohibited fields need a default value, otherwise repr fails

from dataclasses import dataclass, field
from xsdata.models.xsd import Any



@dataclass(kw_only=True)
class Foo:
    bar: Any = field(
        init=False,
        metadata={
            "type": "Ignore",
        },
    )

print(Foo())


  File "/usr/lib/python3.12/dataclasses.py", line 262, in wrapper
    result = user_function(self)
             ^^^^^^^^^^^^^^^^^^^
  File "<string>", line 3, in __repr__
AttributeError: 'Foo' object has no attribute 'bar'

resolve #1091

🔗 What I've Done

Write a description of the steps taken to resolve the issue

💬 Comments

A place to write any comments to the reviewer.

🛫 Checklist

Copy link

codecov bot commented Dec 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (6e3f505) to head (f377f03).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1098   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          115       115           
  Lines         9279      9281    +2     
  Branches      1417      1418    +1     
=========================================
+ Hits          9279      9281    +2     

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

Copy link

sonarqubecloud bot commented Dec 1, 2024

@tefra tefra merged commit 95755fe into main Dec 1, 2024
14 checks passed
@tefra tefra deleted the fix-1091 branch December 1, 2024 04:51
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.

xsdata seems to have an issue with metadata = {"type": "ignore"}
1 participant