question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

kedro.framework.context.context.KedroContextError with Kedro 0.17.0

See original GitHub issue

Description

Short description of the problem here. I kept facing the ModuleNotFoundError then came across this post about the similar issue. Further after implementing the recommended solution (snipet below), I got this error:

_add_src_to_path(Path.cwd()/“src”, Path.cwd()) context = load_context(path_to_project) output = context.run()

Context

How has this bug affected you? What were you trying to accomplish? I was trying to deploy the kedro application on Docker using flask API. But the error occured while implementing the Flask API

Steps to Reproduce

  1. [Create the flask python file] I created the python file containing my flask scripts with the useful imports. Everything works fine while using the default route to test the Flask API Everything breaks when I call the load_context(path_to_project) (snipet below)

@app.route(‘/run’) def run(): _add_src_to_path(Path.cwd()/“src”, Path.cwd()) context = load_context(path_to_project) output = context.run() return output

  1. [Call the run route] Got the kedro.framework.context.context.KedroContextError with the following detail: kedro.framework.context.context.KedroContextError: Failed to find the pipeline named ‘default’. It needs to be generated and returned by the ‘_get_pipelines’ function.

Expected Result

I should receive a JSON outpout showing: {“Model has a coefficient R^2 of 0.456.”}

Actual Result

I face the error explained in step 2. [Call the run route]

 File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/kedro/framework/context/context.py", line 253, in _get_pipeline
    return pipelines[name]
KeyError: '__default__'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/zoumanakeita/Desktop/Personal/Learn_Kedro/iris-kedro/flask-app.py", line 16, in run
    output = context.run()
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/kedro/framework/context/context.py", line 561, in run
    pipeline = self._get_pipeline(name=pipeline_name)
  File "/Users/zoumanakeita/opt/anaconda3/envs/awesome-kedro-project-env/lib/python3.7/site-packages/kedro/framework/context/context.py", line 259, in _get_pipeline
    ) from exc
kedro.framework.context.context.KedroContextError: Failed to find the pipeline named '__default__'. It needs to be generated and returned by the '_get_pipelines' function.

Your Environment

Include as many relevant details about the environment in which you experienced the bug:

  • Kedro version used (pip show kedro or kedro -V): kedro, version 0.17.0
  • Python version used (python -V): Python 3.7.9
  • Operating system and version: MacOS Catanina Version 10.15.4
  • Environment: virtual environment used to run the program
  • Error status: happens when running the Flask Application

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
zoumdatasciencecommented, Jan 25, 2021

Hi @MerelTheisenQB,

Thank you for your feedback, the code that I was not pointing to the correct path of the project, so the step by step debugging (as you suggested) helped me find the issue. So my final code is below:

@app.route('/run')
def run():
    project_path = Path.cwd()
    metadata = _get_project_metadata(project_path)
    _add_src_to_path(metadata.source_dir, project_path)
    session = KedroSession.create(metadata.package_name, project_path)
    context = session.load_context()
    
    output = context.run()
    return output

if __name__ == '__main__':
    app.run(debug=True)

Have a great week!

1reaction
merelchtcommented, Apr 30, 2021

It’s built by kedro, you can use it by importing it like this from kedro.framework.startup import _add_src_to_path 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

kedro.framework.context — Kedro 0.17.0 documentation
kedro.framework.context provides functionality for loading Kedro project context. ... KedroContextError, Error occurred when loading project and running ...
Read more >
kedro.framework.context.context.KedroContextError with ...
Description Short description of the problem here. I kept facing the ModuleNotFoundError then came across this post about the similar issue.
Read more >
Kedro : Failed to find the pipeline named '__default__'
framework.context.context.KedroContextError: Failed to find the pipeline named '__default__'. It needs to be generated and returned by the ...
Read more >
kedro Changelog - pyup.io
Please migrate your project to Kedro>=0.17.0 before you install the latest ... `kedro.framework.context.load_context` will be removed in release 0.18.0.
Read more >
kedro-org/kedro 0.17.0 on GitHub - NewReleases.io
New release kedro-org/kedro version 0.17.0 on GitHub. ... Removed get_static_project_data from kedro.framework.context . Removed KedroContext.static_data .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found