rolldeep opened a new issue #31:
URL: https://github.com/apache/airflow-client-python/issues/31


   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
   import typer
   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)
           typer.echo(f"Created variable: {variable_key}")
       except client.ApiException as e:
           typer.echo(json.loads(e.body)['detail'])
   
   ```
   
   Should we change the default behavior of the airflow-client-python when we 
are trying to create the variable that already exists?


-- 
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]


Reply via email to