-
Notifications
You must be signed in to change notification settings - Fork 789
fix(python-runner): compute full module path so relative imports work #751
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
base: main
Are you sure you want to change the base?
fix(python-runner): compute full module path so relative imports work #751
Conversation
|
@riturajFi is attempting to deploy a commit to the motia Team on Vercel. A member of the Team first needs to authorize it. |
|
Thanks @riturajFi, let me check with the team to review this quickly, thanks! |
|
Checking this asap |
|
Hi @sergiofilhowz, Here’s the detailed process to reproduce the bug and verify the fix: 🧪 Steps to Reproduce (on
|
81b0750 to
592b032
Compare
592b032 to
aeb978a
Compare
1253bc8 to
6640f70
Compare
d6aacf2 to
4325125
Compare
|
|
| const logsPlugin = require('@motiadev/plugin-logs/plugin') | ||
| const observabilityPlugin = require('@motiadev/plugin-observability/plugin') | ||
|
|
||
| export default config({ |
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.
Is this file necessary?
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.
Sorry i placed these by mistake
| @@ -0,0 +1,17 @@ | |||
| /** | |||
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.
Is this file necessary?
| project_root = steps_dir.parent | ||
| project_parent = project_root.parent | ||
| if str(project_parent) not in sys.path: | ||
| sys.path.insert(0, str(project_parent)) |
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.
Do we need to include it at position 0? This will require a bit shift of all elements. If it's not necessary, can we use append?


Closes #746
Problem
The Python step runner was incorrectly setting
module.__package__to only the last directory name (e.g."endpoints").As a result, relative imports like:
failed with:
This prevented Motia from correctly loading step files with nested package structures.
Solution
Updated the runner logic in
get-config.pyto compute the full dotted module path relative to thesteps/directory.Example:
steps/endpoints/python_api_step.py"endpoints""steps.endpoints""steps.endpoints.python_api_step"Set
module.__package__andsys.modules[...]to this full dotted name before executing the module.This ensures Python has the correct package context, so relative imports always resolve properly.
Screencast.from.2025-10-01.09-54-08.webm
Benefits
..repositories,..utils, etc.) now work across all nested step files.steps/directory.__init__.pyrequired).Example
Before (broken):
After (fixed):