Skip to content
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

Fix a bug where we couldn't execute imported functions #259

Merged
merged 4 commits into from
Jul 27, 2022

Conversation

likawind
Copy link
Contributor

@likawind likawind commented Jul 26, 2022

Describe your changes and why you are making these changes

This PR fixes the bug that we couldn't execute imported functions like the following:

from external import func

@aqueduct.op(file_dependencies=["external.py"])
def copy_field(df):
    return func(df)

copy_field(inputs).get()

Specifically, we fixed the sys.path which we used to import user functions to make sure the dependencies also properly appears in sys.path. We also added a few debugging logs for the extracted operator files.

Related issue number (if any)

ENG-1451

Checklist before requesting a review

Verified the code snippet above works after fix

  • I have created a descriptive PR title. The PR title should complete the sentence "This PR...".
  • I have performed a self-review of my code.
  • [na] I have included a small demo of the changes. For the UI, this would be a screenshot or a Loom video.
  • [na] If this is a new feature, I have added unit tests and integration tests.
  • [na] (in-PR tests should be sufficient) I have run the integration tests locally and they are passing.
  • I have run the linter script locally (See python3 scripts/run_linters.py -h for usage).
  • [na] All features on the UI continue to work correctly.
  • Added one of the following CI labels:
    • run_integration_test: Runs integration tests
    • skip_integration_test: Skips integration tests (Should be used when changes are ONLY documentation/UI)

@likawind likawind requested review from kenxu95, cw75 and Fanjia-Yan July 26, 2022 23:51
@likawind likawind added the run_integration_test Triggers integration tests label Jul 26, 2022
Copy link
Contributor

@cw75 cw75 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits otherwise LGTM!


# work_dir should be `<storage>/operators/<id>/op`
work_dir = os.path.join(fn_path, OP_DIR)
print("listdir workdir")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be a bit more descriptive here: "Listing files under the current working directory." The reason being I feel others may have a hard time understanding what listdir workdir means.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I think it is kind of confusing what listdir and workdir represent, might need some documentation or clarification there.

Comment on lines 58 to 59
print("listdir fn path")
print(os.listdir(fn_path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the purpose of fn_path is just to construct the work_dir which is what we need, so I don't see a strong motivation for us to print out fn_path anymore.

import_path = _get_py_import_path(spec)
print(f"import_path: {import_path}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest using a full sentence for clarity: f"The model import path is: {import_path}."

Copy link
Contributor

@kenxu95 kenxu95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay! Left a few comments



def _import_invoke_method(spec: FunctionSpec) -> Callable[..., DataFrame]:
# `_import_invoke_method` imports the model object.
# it assumes the operator has been extracted to `<storage>/operators/<id>/op`
# and imports the route from the above path.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does "route" mean here?

nit: can we use the """ format for docstrings? I looks like its the standard and also looks way better on my IDE :D https://peps.python.org/pep-0257/

print("listdir fn path")
print(os.listdir(fn_path))
os.chdir(work_dir)
sys.path.append(work_dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we comment this line? I think its important that a reader knows what the purpose of this specific line is, and what failure case can occur when its not included.

print("listdir workdir")
print(os.listdir(work_dir))
print("listdir fn path")
print(os.listdir(fn_path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a tiny tiny readability preference to merge the prefix and the list into one line ala "listdir(fn_path): %s" % os.listdir(fn_path)

Copy link
Contributor

@Fanjia-Yan Fanjia-Yan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for the fix.


# work_dir should be `<storage>/operators/<id>/op`
work_dir = os.path.join(fn_path, OP_DIR)
print("listdir workdir")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I think it is kind of confusing what listdir and workdir represent, might need some documentation or clarification there.

@likawind likawind merged commit 89e3863 into main Jul 27, 2022
@likawind likawind deleted the eng-1451-fix-a-bug-where-we-could-execute branch July 27, 2022 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run_integration_test Triggers integration tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants