-
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 logic to activate and deactivate KedroSession
#1431
Comments
I think we should take care here to understand exactly why this code exists in the first place and what would be the consequences of making this change, i.e. what will behave differently after removing this code. Presumably it was originally put there for a good reason to handle some particular cases. Maybe such cases are no longer possible now we have one run session, or maybe they're so marginal that we don't care about them. But it would be good to understand the context of why this logic is here currently. |
@AntonyMilneQB I checked the repository the The activate/deactivate session mechanism doesn't look necessary to me, in fact, if you just do This will run
However, there is a kedro/tests/framework/session/test_session.py Lines 521 to 532 in 307783b
It was created since Ipython extension exists. [KED-1996] Create an IPython extension for Kedro (#853) · 80e2202 · GitHub](80e2202) |
I beg you to not make this change (i.e. not merge #1434) this before you manage to provide a solution for #1411. Many plugins (including The key idea is that we theoretically should be able to do the following : import settings
config_loader=settings.CONFIG_LOADER_CLASS(*settings.CONFIG_LOADER_ARGS) inside a hook to retrieve some configuration. However, we have no way to retrieve the environment ( Notice that none of the workaround described in #506 works with 0.18. The discussion in #1411 shows that we could be able to create a custom context which would export the variable as an environment variable, and then get it back when needed but this looks that an horrible solution and I would hate having to force I hope I was convincing :) P.S: Obviously, when #1411 will be solved natively in the core library, this would make sense to get rid of this global variable. |
@Galileo-Galilei A quick question before I finished reading all the issues. The problem is you no longer have access to session/context/config loader, which is probably already a problem since the removal of |
Hi, I currently recreate the |
@Galileo-Galilei Thanks very much for your comments here. I for one am convinced by your plea! I thought I had a workaround here since
... but I'm not immediately sure where we can get I've reopened #506. Sorry your comments on this were not noticed before (for future reference, I think many people don't notice Github notifications - if you really need something then probably best to send a message on discord so it doesn't get overlooked). Ultimately, as I understand it, the fundamental problem here is that there has never been a good way to access the Just to add some further context here, let me copy a discussion we had when the code around
There was some user research conducted around whether anyone used However, it seems that the very important case of plugin authors was not considered here. I wish we had seen #506 at the time, because that makes it clear that it would be valuable to have the Do you think one of the other options (a-c) makes sense here? If access to the |
In
def _export_credentials(self, session: KedroSession = None):
session = session or _get_current_session()
context = session.load_context()
conf_creds = context._get_config_credentials()
mlflow_creds = conf_creds.get(self.server.credentials, {})
for key, value in mlflow_creds.items():
os.environ[key] = value def get_mlflow_config(session: Optional[KedroSession] = None):
session = session or _get_current_session()
context = session.load_context()
try:
conf_mlflow_yml = context._config_loader.get("mlflow*", "mlflow*/**")
except MissingConfigException:
raise KedroMlflowConfigError(
"No 'mlflow.yml' config file found in environment. Use ``kedro mlflow init`` command in CLI to create a default config file."
)
conf_mlflow_yml["project_path"] = context.project_path
mlflow_config = KedroMlflowConfig.parse_obj(conf_mlflow_yml)
return mlflow_config |
Thank you both for your answers and the time you dedicated to find out a solution for this. Comments on your answers
I actually found the exact same things and I was about to write that it it seems to work, since This solves the problem for
I almost agree. Accessing the Functional use casesThe 2 identified use cases where the context is needed are summarized by @noklam above:
I think the problem depends more on where we want to access these informations rather than what we want to do with them:
with KedroSession.create(project_path, env) as session:
get_mlflow_config(session) # <- you don't need an active session, the user can pass the session (or the needed information) "manually" => no real issue here
Potential solutions
class MyHook():
@hook_impl
def before_pipeline_run(
self, run_params: Dict[str, Any], pipeline: Pipeline, catalog: DataCatalog
) -> None:
self._config_loader= settings.CONFIG_LOADER_CLASS(
conf_source=(Path(run_params["project_path"]) / settings.CONF_SOURCE).as_posix(),
env=run_params["env"],
runtime_params=run_params,
**settings.CONFIG_LOADER_ARGS,
)
@hook_impl
def before_node_run(
self, node: Node, catalog: DataCatalog, inputs: Dict[str, Any], is_async: bool
) -> None:
self._config_loader.get("whatever") # self._config_loader is accessible
Finally, I think that:
What to doI will give a try in |
Thanks very much @Galileo-Galilei, that all makes a lot of sense and is very useful. What you're trying to do in I think this should work well actually (especially because you found
I'm not sure how much I like this, but it does work well. On the one hand, doing it a lot probably indicates that we're not making the right things available in the right hooks; but it does mean that we don't have to pass I still regard this as a bit of a workaround because requiring the user/plugin author to do I left a couple of questions in #506 about what we should actually make available in the hooks 🙂 P.S. unless I'm missing something, adding an argument to a hook specification shouldn't be a breaking change since I believe you need to always write |
KedroSession is still keeping a global for the currently active session, which causes problems when trying to create a session in a notebook with the Kedro IPython extension and makes it unable to create/run the session. Here's the functions we need to drop:
https://github.com/kedro-org/kedro/blob/main/kedro/framework/session/session.py#L34-L47
And here is where they are used: https://github.com/kedro-org/kedro/blob/main/kedro/framework/session/session.py#L274-L287
Need to add a regression test:
The text was updated successfully, but these errors were encountered: