Skip to content

Commit

Permalink
fix: Prohibited fields need default value None
Browse files Browse the repository at this point in the history
resolve #1091
  • Loading branch information
tefra committed Dec 1, 2024
1 parent 6e3f505 commit 360ba1a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/formats/dataclass/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def test_field_definition_with_prohibited_attr(self):
expected = (
"field(\n"
" init=False,\n"
" default=None,\n"
" metadata={\n"
' "type": "Ignore",\n'
" }\n"
Expand Down
1 change: 1 addition & 0 deletions xsdata/formats/dataclass/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def field_definition(
kwargs: Dict[str, Any] = {}
if attr.fixed or attr.is_prohibited:
kwargs["init"] = False
kwargs[self.DEFAULT_KEY] = None

if default_value is not False and not attr.is_prohibited:
key = self.FACTORY_KEY if attr.is_factory else self.DEFAULT_KEY
Expand Down

0 comments on commit 360ba1a

Please sign in to comment.