Dev-iL commented on code in PR #57532:
URL: https://github.com/apache/airflow/pull/57532#discussion_r2484256597
##########
airflow-core/src/airflow/models/variable.py:
##########
@@ -242,31 +242,48 @@ def set(
is_encrypted = new_variable.is_encrypted
# Import dialect-specific insert function
- if (dialect_name := session.get_bind().dialect.name) ==
"postgresql":
- from sqlalchemy.dialects.postgresql import insert
- elif dialect_name == "mysql":
- from sqlalchemy.dialects.mysql import insert
- else:
- from sqlalchemy.dialects.sqlite import insert
+ dialect_name = get_dialect_name(session)
+ stmt: Any
+ if dialect_name == "postgresql":
+ from sqlalchemy.dialects.postgresql import insert as pg_insert
- # Create the insert statement (common for all dialects)
- stmt = insert(Variable).values(
- key=key,
- val=val,
- description=description,
- is_encrypted=is_encrypted,
- )
Review Comment:
I'm not sure if this is viable, but perhaps instead of duplicating the code
it's possible to do one of the below:
1. Add a helper function to handle insert via "dependency injection"
```python
Statement: type = <a hint for statements that's more specific than `Any`,
perhaps `ClauseElement`>
def dialect_insert(insert_method: Callable[[Variable], Statement]) ->
Statement:
return insert(Variable).values(
key,
val,
description,
is_encrypted,
)
```
2. Add an appropriate type hint for `insert`, such as
`sqlalchemy.sql.dml.Insert`
--
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]