Visitar URL original
Error earlier if virtualenv is not installed and DAG has a PythonVirtualenvOperator by MatrixManAtYrService · Pull Request #15788 · apache/airflow · GitHub
Skip to content

Error earlier if virtualenv is not installed and DAG has a PythonVirtualenvOperator - #15788

Merged
potiuk merged 1 commit into
apache:mainfrom
MatrixManAtYrService:virtualenv_error_early
Aug 1, 2021
Merged

potiuk merged 1 commit into
apache:mainfrom
MatrixManAtYrService:virtualenv_error_early

Conversation

@MatrixManAtYrService

Copy link
Copy Markdown
Contributor

While trying to use @task.virtualenv I got this error:

 File "/Users/matt/src/airflow/airflow/models/taskinstance.py", line 1340, in _execute_task
    result = task_copy.execute(context=context)
  File "/Users/matt/src/airflow/airflow/decorators/base.py", line 138, in execute
    return_value = super().execute(context)
  File "/Users/matt/src/airflow/airflow/operators/python.py", line 350, in execute
    return super().execute(context=serializable_context)
  File "/Users/matt/src/airflow/airflow/operators/python.py", line 152, in execute
    return_value = self.execute_callable()
  File "/Users/matt/src/airflow/airflow/operators/python.py", line 362, in execute_callable
    prepare_virtualenv(
  File "/Users/matt/src/airflow/airflow/utils/python_virtualenv.py", line 95, in prepare_virtualenv
    execute_in_subprocess(virtualenv_cmd)
  File "/Users/matt/src/airflow/airflow/utils/process_utils.py", line 136, in execute_in_subprocess
    with subprocess.Popen(
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'virtualenv'

It was helpful enough that I was able to guess that pip install virtualenv would fix things for me, but:

  • The error could have come up earlier
  • FileNotFoundError made me doubt that it was a packaging issue

This PR checks if virtualenv is importable at init time and throws a more helpful exception.

I'm interested to know if there's a better way to handle things like this, but this is at least better than how it was.

@boring-cyborg

boring-cyborg Bot commented May 12, 2021

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@ashb ashb added this to the Airflow 2.2 milestone May 18, 2021
@github-actions

Copy link
Copy Markdown
Contributor

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions Bot added the full tests needed We need to run full set of tests for this PR to merge label May 18, 2021
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jul 19, 2021
@uranusjr

Copy link
Copy Markdown
Member

Technically PythonVirtualenvOperator does not require virtualenv to be installed in the same environment as Airflow, but only that virtualenv command is available in PATH. I would use shutil.which("virtualenv") to detect its existence instead.

@github-actions github-actions Bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Jul 20, 2021
@potiuk

potiuk commented Aug 1, 2021

Copy link
Copy Markdown
Member

Hey @MatrixManAtYrService - can you please rebase it to the latest main (it should be conflict-less)

@MatrixManAtYrService

Copy link
Copy Markdown
Contributor Author

Oops, must've overlooked the earlier notification.

  • switched to shutil.which("virtualenv")
  • rebased onto main

@potiuk

potiuk commented Aug 1, 2021

Copy link
Copy Markdown
Member

Temporary errors only :)

@potiuk
potiuk merged commit 6cc2526 into apache:main Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full tests needed We need to run full set of tests for this PR to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants