fix: initialize doc with dataclass obj and kwargs#694
Conversation
Codecov Report
@@ Coverage Diff @@
## main #694 +/- ##
=======================================
Coverage 88.50% 88.50%
=======================================
Files 133 133
Lines 6542 6542
=======================================
Hits 5790 5790
Misses 752 752
Flags with carried forward coverage won't be shown. Click here to find out more. Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
JohannesMessner
left a comment
There was a problem hiding this comment.
Looking good!
But can we have a test where we see how conflicting fields are handled?
I think if you use a basic type like str in the data class it will be put in the tags of the top level Document. What happens if I then also set tags as **kwargs? What if the keys in these two different tag dictionaries clash, what if they don't?
|
Ok, makes sense, I will check that out and add a test accordingly |
|
How do we expect the Document to behave incase it is initialized as follows: def test_doc_with_dataclass_with_str_attr_and_additional_unknown_attr_with_same_name():
@dataclass
class MyDoc:
name: str
d = Document(MyDoc(name='mydoc'), name='doc')
assert d.tags['name'] == 'doc'
assert d.tags['name'] == 'mydoc' # failsIn this case, tags['name'] is being set to 'mydoc' first and then overwritten with 'doc' afterwards. |
Goals:
Documentinstance with a dataclass obj as well as additionalkwargs.Documentinstance, due to the fact of overwritingself._data, as described here: Bug: initializing Document with dataclass and additional kwargs #447Example