Airflow DB session not providing any environement vabiable
<p>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: </p>

<pre><code>import os
from airflow.models import Variable

print(os.environ['SHELL'])
local_env['SHELL'] = Variable.get('SHELL')
</code></pre>

<p>And I got following error:</p>

<blockquote>
  <p>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</p>
</blockquote>

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

<pre><code>    @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))
</code></pre>

<p>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? </p>

<p>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: </p>

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

<p>Anything I missed when setting up the airflow? 
Thanks,</p>

<p>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. </p>

python airflow