jason810496 commented on code in PR #48547:
URL: https://github.com/apache/airflow/pull/48547#discussion_r2029837534
##########
airflow-core/src/airflow/models/variable.py:
##########
@@ -202,14 +202,136 @@ def set(
else:
stored_value = str(value)
- Variable.delete(key, session=session)
- session.add(Variable(key=key, val=stored_value,
description=description))
+ new_variable = Variable(key=key, val=stored_value,
description=description)
+
+ # Perform dialect-specific upsert operation
+ dialect_name = session.get_bind().dialect.name
+ if dialect_name == "postgresql":
+ Variable._postgres_upsert_variable(
+ key=key,
+ val=new_variable._val,
+ is_encrypted=new_variable.is_encrypted,
+ description=description,
+ session=session,
+ )
+ elif dialect_name == "mysql":
+ Variable._mysql_upsert_variable(
+ key=key,
+ val=new_variable._val,
+ is_encrypted=new_variable.is_encrypted,
+ description=description,
+ session=session,
+ )
+ elif dialect_name == "sqlite":
+ Variable._sqlite_upsert_variable(
+ key=key,
+ val=new_variable._val,
+ is_encrypted=new_variable.is_encrypted,
+ description=description,
+ session=session,
+ )
Review Comment:
Thanks for the update!
I think we don’t need to have separate _upsert_variable_<dialect> functions
for each dialect. The only difference between Postgres and SQLite seems to be
the import path for insert, while all statement structure is the same.
For MySQL with the others, only the on_conflict_do_update or
on_duplicate_key_update parts differ, the base statement is the same, so we
could probably consolidate the logic and handle the dialect-specific behavior
with minimal branching.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]