ashb commented on a change in pull request #4819: [AIRFLOW-3997] Add getter to 
Variable that returns None instead of throwing
URL: https://github.com/apache/airflow/pull/4819#discussion_r263329660
 
 

 ##########
 File path: airflow/models/__init__.py
 ##########
 @@ -4263,6 +4263,14 @@ def setdefault(cls, key, default, 
deserialize_json=False):
         else:
             return obj
 
+    @classmethod
+    @provide_session
+    def try_get(cls, key, deserialize_json=False, session=None):
+        try:
+            return cls.get(key, deserialize_json=deserialize_json, 
session=session)
+        except KeyError:
+            return None
 
 Review comment:
   I _think_ it's probably a rare-enough case that it won't affect many people.
   
   Still, we should add a note to UPDATING.md saying something along the lines 
of "if you want the old behaviour of raising when  the variable is not found, 
ensure `default_var` is not passed"

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


With regards,
Apache Git Services

Reply via email to