1
resposta

[Bug] Airflow não executa

Estou com um problema ao executar o airflow pelo "airflow standalone", quando rodo recebo esse erro:

standalone | Starting Airflow Standalone
standalone | Checking database is initialized
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 849da589634d -> 2c6edca13270, Resource based permissions.
Traceback (most recent call last):
  File "/home/ununtu/Documents/airflow_alura/venv/bin/airflow", line 8, in <module>
    sys.exit(main())
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/__main__.py", line 38, in main
    args.func(args)
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/cli/cli_parser.py", line 51, in command
    return func(*args, **kwargs)
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/cli/commands/standalone_command.py", line 48, in entrypoint
    StandaloneCommand().run()
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/cli/commands/standalone_command.py", line 64, in run
    self.initialize_database()
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/cli/commands/standalone_command.py", line 172, in initialize_database
    db.initdb()
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/utils/session.py", line 71, in wrapper
    return func(*args, session=session, **kwargs)
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/utils/db.py", line 648, in initdb
    upgradedb(session=session)
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/utils/session.py", line 68, in wrapper
    return func(*args, **kwargs)
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/utils/db.py", line 1449, in upgradedb
    command.upgrade(config, revision=to_revision or 'heads')
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/alembic/command.py", line 322, in upgrade
    script.run_env()
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/alembic/script/base.py", line 569, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 94, in load_python_file
    module = load_module_py(module_id, path)
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 110, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/migrations/env.py", line 107, in <module>
    run_migrations_online()
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/migrations/env.py", line 101, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/alembic/runtime/environment.py", line 853, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/alembic/runtime/migration.py", line 623, in run_migrations
    step.migration_fn(**kw)
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/migrations/versions/0074_2_0_0_resource_based_permissions.py", line 342, in upgrade
    remap_permissions()
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/migrations/versions/0074_2_0_0_resource_based_permissions.py", line 290, in remap_permissions
    appbuilder = create_app(config={'FAB_UPDATE_PERMS': False}).appbuilder
  File "/home/ununtu/Documents/airflow_alura/venv/lib/python3.9/site-packages/airflow/www/app.py", line 84, in create_app
    raise AirflowConfigException(
airflow.exceptions.AirflowConfigException: Cannot use relative path: `sqlite:///~Documents/airflow_alura/airflow.db` to connect to sqlite. Please use absolute path such as `sqlite:////tmp/airflow.db`.
1 resposta

Oi, Caíque. Tudo bem por aí?

O erro indica que o Airflow não suporta caminhos relativos para conectar ao SQLite, e ele precisa de um caminho absoluto. E logo diz que você não pode usar um caminho relativo, como sqlite:///~Documents/airflowalura/airflow.db, mas sim um caminho absoluto, como sqlite:////tmp/airflow.db.

Verifique se executou certinho todos os passos da aula.

Como sugestão, caso o erro persista, você ajustar a variável de ambiente AIRFLOW_HOME para o caminho absoluto do diretório onde você deseja que o banco de dados seja criado, assim:

export AIRFLOW_HOME=/home/ununtu/Documents/airflow_alura

E, então, rode novamente o airflow standalone.

Fico na torcida para dar tudo certo!

Abração.

Caso este post tenha lhe ajudado, por favor, marcar como solucionado ✓. Bons Estudos!