Airflow DB session not providing any environement vabiable
Question: As an Airflow and Python newbie, even don't know if I'm asking the right
question, but asking anyway. I've configured airflow on a CentOS system. Use
remote MySql instance as the backend. In my code, need to get a number of
Variables, the code looks like below:

    
    
    import os
    from airflow.models import Variable
    
    print(os.environ['SHELL'])
    local_env['SHELL'] = Variable.get('SHELL')
    

And I got following error:

> Traceback (most recent call last): File "test2.py", line 5, in
> local_env['SHELL'] = Variable.get('SHELL') File
> "/com/work/airflowenv/lib/python2.7/site-packages/airflow/utils/db.py", line
> 53, in wrapper result = func(*args, **kwargs) File
> "/com/work/airflowenv/lib/python2.7/site-packages/airflow/models.py", line
> 3134, in get raise ValueError('Variable {} does not exist'.format(key))
> ValueError: Variable SHELL does not exist

It is the Variable.get() method throws the exception in this piece of code in
models.py:

    
    
        @classmethod
        @provide_session
        def get(cls, key, default_var=None, deserialize_json=False, session=None):
            obj = session.query(cls).filter(cls.key == key).first()
            if obj is None:
                if default_var is not None:
                    return default_var
                else:
                    raise ValueError('Variable {} does not exist'.format(key))
    

Where session.query already yield None. Don't quite understand how the session
is injected here. and why these session variables not set. Should we set up
something on the remote MySQL instance?

BTW, we have another identical airflow instance on another machine with local
mysql instance. And running the script I provided stand alone has no problem:

> [2016-09-27 01:54:48,341] {**init**.py:36} INFO - Using executor
>
> LocalExecutor
>
> /bin/bash /bin/bash

Anything I missed when setting up the airflow? Thanks,


Answer: Ok, finally got the problem resolved. What I've done is print out the query,
and figured out the variable must be from some relational database table
called variable. And dig into the backend DB, found the DB, made the
comparation between it and the working one, and figured out that the
"variable" table data missed. The way to add these variable is simple: airflow
variables -s SHELL /bin/bash and so forth for other variables.

