Skip to content

🐍 Add Pydantic extra="allow" to Geschaeftsobjekt and COM base classes#439

Merged
hf-kklein merged 2 commits intomainfrom
extra-allow
Dec 14, 2022
Merged

🐍 Add Pydantic extra="allow" to Geschaeftsobjekt and COM base classes#439
hf-kklein merged 2 commits intomainfrom
extra-allow

Conversation

@hf-kklein
Copy link
Copy Markdown
Contributor

This allows to deserialized unmatched properties

This allows to deserialized unmatched properties
@hf-kklein hf-kklein self-assigned this Dec 7, 2022
Comment on lines +71 to +76
er = ExterneReferenz(ex_ref_name="foo.bar", ex_ref_wert="12345")
er_json: Dict[str, Any] = er.dict()
er_json["additional_key"] = "additional_value"
deserialized_er: ExterneReferenz = ExterneReferenz.parse_obj(er_json)
assert isinstance(deserialized_er, ExterneReferenz)
assert deserialized_er.additional_key == "additional_value" # type:ignore[attr-defined]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nur für mein Verständnis, das hätte auch ohne das extra = "allow" geklappt oder?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nein, genau dafür is extra="allow" da. Siehe

 def test_extension_data(self) -> None:
   """
   tests the behaviour of the json extension data (`extra="allow"`)
   """
   er = ExterneReferenz(ex_ref_name="foo.bar", ex_ref_wert="12345")
   er_json: Dict[str, Any] = er.dict()
   er_json["additional_key"] = "additional_value"
   deserialized_er: ExterneReferenz = ExterneReferenz.parse_obj(er_json)
   assert isinstance(deserialized_er, ExterneReferenz)
  assert deserialized_er.additional_key == "additional_value"  # type:ignore[attr-defined]

E AttributeError: 'ExterneReferenz' object has no attribute 'additional_key'

#441

@hf-kklein hf-kklein merged commit dbde2c7 into main Dec 14, 2022
@hf-kklein hf-kklein deleted the extra-allow branch December 14, 2022 10:05
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.

2 participants