You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2018/12/24 00:13:11 UTC

[GitHub] stale[bot] closed pull request #3142: [AIRFLOW-2227] allow the ability to delete an airflow variable using the variable class

stale[bot] closed pull request #3142: [AIRFLOW-2227] allow the ability to delete an airflow variable using the variable class 
URL: https://github.com/apache/incubator-airflow/pull/3142
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/models.py b/airflow/models.py
index c1b608afbb..549e990ffd 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -4285,6 +4285,27 @@ def set(cls, key, value, serialize_json=False, session=None):
         session.add(Variable(key=key, val=stored_value))
         session.flush()
 
+    @classmethod
+    @provide_session
+    def delete(cls, key, session=None):
+        try:
+            session.query(cls).filter(cls.key == key).delete()
+            session.commit()
+        except Exception as e:
+            session.rollback()
+            logging.warning("Failed to delete key {}".format(key))
+            logging.exception(e)
+
+    @classmethod
+    @provide_session
+    def get_keys(cls, session=None):
+        try:
+            keys = {obj.key for obj in session.query(cls).all()}
+            return keys
+        except Exception as e:
+            logging.warning("Failed to retrieve variables keys")
+            logging.exception(e)
+
 
 class XCom(Base, LoggingMixin):
     """


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services