-
Notifications
You must be signed in to change notification settings - Fork 926
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
Remove KedroSession activate/deactivate mechanism #1434
Conversation
…ons can be created. Signed-off-by: noklam <[email protected]>
Signed-off-by: noklam <[email protected]>
…b.com/kedro-org/kedro into feat/activate-deactivate-kedrosession Signed-off-by: noklam <[email protected]>
@Galileo-Galilei I am checking on the comments and older Github issue. Your concerns are valid and this won't be merged until further discussed. I can see why this is important for plugins. Thank you for your detailed comments. |
Thank you very much! |
Notes:
|
…sm." This reverts commit dc422f3. Signed-off-by: noklam <[email protected]>
…b.com/kedro-org/kedro into feat/activate-deactivate-kedrosession Signed-off-by: noklam <[email protected]>
Signed-off-by: noklam <[email protected]>
Signed-off-by: noklam <[email protected]>
Ready for review again, but we need to make sure it is merged only after #1458 and release them both in |
kedro/framework/session/session.py
Outdated
def _activate_session( | ||
session: "KedroSession", force: bool = False # pylint: disable=unused-argument | ||
) -> None: | ||
global _active_session | ||
|
||
if _active_session and not force and session is not _active_session: | ||
raise RuntimeError( | ||
"Cannot activate the session as another active session already exists." | ||
) | ||
|
||
_active_session = session |
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.
Given that #1458 is a prerequisite for this, will we need any of this stuff at all any more?
I'm a bit confused by whether the plan is to simultaneously do both of these:
- introduce
after_context_created
hook - remove all the
_active_session
stuff
Or whether we want to do:
- remove
_activate_session
stuff but leave_active_session
global there - introduce
after_context_created
hook - remove all the
_active_session
stuff
i.e. do we do a straight swap in 0.18.1 (replace all _active_session
things with the new hook) or do we do a phased introduction (in 0.18.1 you can use _active_session
OR the new hook; then in 0.18.2 you can only use the new hook)?
Would be good to know if this affects @Galileo-Galilei 🙂
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.
I think the idea is to do 1&2 together in 0.18.1
. Doing 1 only would leave the _active_session
None only? Sorry I found that there are commits in my local repository but never pushed to the remote once as I was switching between these related branches.
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.
Ah ok, that makes sense! It looks much more like I was expecting after your push 😀
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.
For what it's worth, I am completely ok with scenario (1), i.e. shipping the new hook and removing the session activation mechanism simultaneously in kedro==0.18.1. This is a private method and I think we can safely assume that people using my dirty hack of importing the global variable in their own plugin know what they are doing and accept the inherent risk of doing so.
There is always a possibility that we miss something and that releasing everything at the same time will eventually break the plugin with no workaround at the plugin level. I'll come back complaining in a new issue if it were to happen 😄. I have some concerns about the current proposal to make the context "frozen", but I'll let a comment in the other PR.
new_session = KedroSession.create(mock_package_name, fake_project) | ||
_activate_session(new_session) | ||
assert kedro.framework.session.session._active_session is new_session | ||
|
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.
Would it be possible to do the context manager of this just to check it works the same way?
with KedroSession.create() as first_session:
assert kedro.framework.session.session._active_session is first_session
with KedroSession.create() as new_session:
assert kedro.framework.session.session._active_session is new_session
assert kedro.framework.session.session._active_session is new_session ## is that right?
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.
Ah, I see that now that _active_session
no longer exists it's not possible to test as you had before and in my above comment. But would it be possible to make this a little more explicit somehow? Something like this maybe?
@pytest.mark.usefixtures("mock_settings")
def test_create_multiple_sessions(self, fake_project, mock_package_name):
with KedroSession.create(mock_package_name, fake_project) as session1:
with KedroSession.create(mock_package_name, fake_project) as session2:
assert session1 is not session2
Also I quite liked having the separate test you had before for the non-context manager version like this:
@pytest.mark.usefixtures("mock_settings")
def test_create_multiple_sessions(self, fake_project, mock_package_name):
session1 = KedroSession.create(mock_package_name, fake_project)
session2 = KedroSession.create(mock_package_name, fake_project)
assert session1 is not session2
But maybe there's no point doing that - up to you!
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.
I think it makes sense to check that it's now possible to create two sessions without it failing, like it did previously.
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.
Just a small comment on the tests but definitely happy to see this change!
new_session = KedroSession.create(mock_package_name, fake_project) | ||
_activate_session(new_session) | ||
assert kedro.framework.session.session._active_session is new_session | ||
|
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.
Ah, I see that now that _active_session
no longer exists it's not possible to test as you had before and in my above comment. But would it be possible to make this a little more explicit somehow? Something like this maybe?
@pytest.mark.usefixtures("mock_settings")
def test_create_multiple_sessions(self, fake_project, mock_package_name):
with KedroSession.create(mock_package_name, fake_project) as session1:
with KedroSession.create(mock_package_name, fake_project) as session2:
assert session1 is not session2
Also I quite liked having the separate test you had before for the non-context manager version like this:
@pytest.mark.usefixtures("mock_settings")
def test_create_multiple_sessions(self, fake_project, mock_package_name):
session1 = KedroSession.create(mock_package_name, fake_project)
session2 = KedroSession.create(mock_package_name, fake_project)
assert session1 is not session2
But maybe there's no point doing that - up to you!
Co-authored-by: Antony Milne <[email protected]>
@AntonyMilneQB With the global (Edited: I think we can now only do this after the |
new_session = KedroSession.create(mock_package_name, fake_project) | ||
_activate_session(new_session) | ||
assert kedro.framework.session.session._active_session is new_session | ||
|
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.
I think it makes sense to check that it's now possible to create two sessions without it failing, like it did previously.
Signed-off-by: noklam <[email protected]>
Signed-off-by: noklam <[email protected]>
…b.com/kedro-org/kedro into feat/activate-deactivate-kedrosession Signed-off-by: noklam <[email protected]>
Signed-off-by: noklam [email protected]
Development Notes
_active_session
all together in favor of the relatedafter_context_created
hook.Description
Close #1431 (Copied from #1431)
I checked the repository the
_activate_session()
and the global_active_session
are only used by ipython.py and theKedroSession
's context manager. It was also used byget_current_session()
but it no longer exists now.The activate/deactivate session mechanism doesn't look necessary to me, in fact, if you just do
session.run()
today it runs perfectly fine. This whole activate/deactivate thing only stops you if you are using context manager.Based on our discussion, it looks like we only want to do 1., but we should just do 2. unless there are some use cases we missed.
Update the logic so a session can be created with the existing active session (this was already possible before, it just doesn't work with the Context Manager style of session. However, this essentially means we do not care if there are pre-exist
_active_session
.Remove the activate/deactivate altogether, since the global
_active_session
is not used by anyone (was used byget_current_session
). But since we allow multiple sessions and there is no practical use to keep track of "active".Development notes
_active_session
Checklist
RELEASE.md
file