From 9c3606886be1c050f4dbe68583836654b1653b87 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Tue, 16 Jun 2015 09:25:16 -0700 Subject: [PATCH] Adding utility function to get to models.Variable --- airflow/models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/airflow/models.py b/airflow/models.py index 570b5ef69ac8d..7d0faabf618be 100644 --- a/airflow/models.py +++ b/airflow/models.py @@ -3,6 +3,7 @@ import getpass import imp import jinja2 +import json import logging import os import dill @@ -1784,6 +1785,15 @@ class Variable(Base): def __repr__(self): return '{} : {}'.format(self.key, self.val) + @classmethod + @provide_session + def get(cls, key, session, deserialize_json=False): + obj = session.query(cls).filter(cls.key == key).first() + v = obj.val + if deserialize_json and v: + v = json.loads(v) + return v + class Pool(Base): __tablename__ = "slot_pool"