Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions airflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems suspect - why do we want to commit the session here - shouldn't the caller be in change of the session instead?

except Exception as e:
session.rollback()
logging.warning("Failed to delete key {}".format(key))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"variable", not key.

logging.exception(e)

@classmethod
@provide_session
def get_keys(cls, session=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this method for?

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):
"""
Expand Down