-
Notifications
You must be signed in to change notification settings - Fork 31
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
[BUGFIX] Fix Context initialization with another Context object #160
[BUGFIX] Fix Context initialization with another Context object #160
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning
The change itself is not wrong but the Context
class needs to be reviewed (and related tests as well).
Can you elaborate on what you mean? Not sure I follow |
For example, do you expect the following |
And here is some Context magic: make |
Yes, this is intended. Idea is that Context is additive in nature. Meaning, if you initiate a Context from other existing contexts, that they get 'soft merged' - more proper merge behavior is expected to be controlled through the merge method though. |
This won't work. The idea is that you want any nested instance of Context to also be made into dicts - hence the code as it sits. Feel free to experiment though, if you wish :) |
I am not talking about the additive aspect. Do you expect
Did you run the tests with that one-liner? Is "This won't work" an assumption or a confirmation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Yup - this works.
Yes. example: nested_context = Context(a=Context(b=Context(c=42)))
# {'a': {'b': {'c': 42}}}
for key, value in nested_context.__dict__.items():
print(f"{key = }")
print(f"{value = }")
print(f"{type(value) = }")
# key = 'a'
# value = {'b': {'c': 42}}
# type(value) = <class 'koheesio.context.Context'>
for key, value in nested_context.to_dict().items():
print(f"{key = }")
print(f"{value = }")
print(f"{type(value) = }")
# key = 'a'
# value = {'b': {'c': 42}}
# type(value) = <class 'dict'> |
Well, I see it is already merged, but I'll say this anyway:
And if you modify
Not only this one but all your context-related tests will still succeed. Let that sink in. |
Description
The init method of the Context class incorrectly updated the
kwargs
making it returnNone
. This means that calls to Context containing another Context object, would previously fail.Related Issue
Closes #159
How Has This Been Tested?
Several unit tests were added to cover the intended behavior - this was previously not covered
Screenshots (if appropriate):
Types of changes
Checklist: