Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I init a dag with a Variable param, it raises an Exception

I am using apache-airflow==1.10.0

I get errors that looks like this:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation "variable" does not exist
LINE 2: FROM variable

When I declare tasks like:

 from airflow.models import Variable
 dag = DAG('dag')
 PythonOperator('task_id', ratio=Variable.get('ratio'), dag=dag)

because I don't have a Variable table yet. I get errors that don't affect anything, but how can I prevent this from happening?

like image 535
Rob Avatar asked Dec 20 '18 18:12

Rob


2 Answers

Run airflow upgradedb. It will create all the missing tables.

like image 99
kaxil Avatar answered Nov 15 '22 09:11

kaxil


A workaround (in case airflow upgradedb doesn't work) is to do the following

  1. Remove all the calls to variables in your DAGs code, you can do this by putting all of them into a function set_variables() and commenting it out
  2. Start airflow webserver and create a dummy variable from the variable UI, this will create the Variable table
  3. Now you can uncomment your set_variables(), your programmatic calls to variables will now work since you have the Variable table
like image 31
Alessandro Solbiati Avatar answered Nov 15 '22 07:11

Alessandro Solbiati