Skip to content

BUG: importing MesosExecutor from contrib creates circular imports and suppresses the error #440

Closed

Description

@jlowin

There is a new set of lines that cause big problems (https://github.com/airbnb/airflow/blob/master/airflow/executors/__init__.py#L11) --

# TODO Fix this emergency fix
try:
    from airflow.contrib.executors.mesos_executor import MesosExecutor
except:
    pass

I don't think anything from contrib can be loaded before airflow itself has finished loading, but MesosExecutor is loaded very early. So this chain of imports results:

from airflow.models import DAG (airflow/__init__.py)
 --> from airflow.executors import DEFAULT_EXECUTOR, LocalExecutor (airflow/models.py)
    --> from airflow.contrib.executors.mesos_executor import MesosExecutor (airflow/executors/__init__.py)
        --> import airflow.contrib.hooks (airflow/contrib/__init__.py)
            --> from airflow.hooks.base_hook import BaseHook (airflow/contrib/hooks/ftp_hook.py)

With the result that airflow.hooks is being imported well before it is supposed to be (we've barely even imported models), and this is causing all kinds of problems. Specifically, the ftp_hook isn't able to import a Connection because the import of models.py gets short-circuited. Normally, this would raise some kind of error but the MesosExecutor lines are suppressing it. The result is that airflow is missing chunks of its functionality at import time (though for some reason it becomes available later for certain objects... I don't understand Python internals well enough to guess why).

I think as a rule, an object in contrib can not be loaded as part of the Airflow startup. Contrib objects are like any user-created library -- designed to be instantiated after airflow is available. If MesosExecutor (or any other executors) are required as part of Airflow's internal setup (which seems to be the case), then they either need to live outside contrib or the entire contrib module needs to be rethought.

Activity

  1. changed the title [-]BUG: importing Mesos Executor from contrib creates circular imports and suppresses the error[/-] [+]BUG: importing MesosExecutor from contrib creates circular imports and suppresses the error[/+] on Sep 21, 2015
  2. jlowin commented on Sep 21, 2015

    @jlowin
    MemberAuthor

    #430 might fix this once merged by removing the import statements in contrib/__init__.py

  3. mistercrunch commented on Sep 22, 2015

    @mistercrunch
    Member

    @jlowin #430 was merged, do you still see the circular imports? I don't see them on my end

  4. jlowin commented on Sep 22, 2015

    @jlowin
    MemberAuthor

    Seems ok now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions