"post_variables" method is overwriting an existing variable with the same variable_id.
rolldeep opened this issue · 0 comments
rolldeep commented
I'm creating a variable via airflow-client-python. If the variable exists in a local instance of airflow it overwrites the existing one. There is different behavior when I'm creating the connection with the same conn_id - it throws an exception saying Connection already exist. ID: <conn_id>
.
Here is the code I use:
import getpass
import json
import socket
import airflow_client.client
import etl.utils.templates.variable as variable
from airflow_client import client
from airflow_client.client.api import variable_api
from airflow_client.client.model.variable import Variable
local_user = input("Enter Local Airflow Admin username: ")
local_pass = getpass.getpass("Enter Local Airflow Admin password: ")
local_host = socket.gethostbyname(socket.gethostname())
configuration = airflow_client.client.Configuration(
host=f"{local_host}:8080/api/v1",
username=local_user,
password=local_pass)
with client.ApiClient(configuration) as api_client:
variable_key = "NewVar"
var_api_instance = variable_api.VariableApi(api_client)
new_variable = Variable(key=variable_key,
value=variable.VARIABLE_VALUE)
try:
# Rewrites existing new_variable if it exists
var_api_instance.post_variables(new_variable)
except client.ApiException as e:
print("Exception when calling VariableApi->post_variables: %s\n" % e)
Should we change the default behavior of the airflow-client-python when we are trying to create the variable that already exists?