You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/06/14 07:13:56 UTC

[GitHub] [airflow] DDullahan commented on issue #16374: CLI Connection import command not work

DDullahan commented on issue #16374:
URL: https://github.com/apache/airflow/issues/16374#issuecomment-859263281


   I met the same problem and checked the source code.
   
   In airflow/cli/commands/connection_command.py it loads connections file as a dict, conn_id for key, Connection type for value.
   After that, it calls items() on Connection type which doesn't have.
      
   ```python
   def _import_helper(file_path):
       """Helps import connections from a file"""
       connections_dict = load_connections_dict(file_path)
       with create_session() as session:
           for conn_id, conn_values in connections_dict.items():
               # type(conn_id) is str
               # type(conn_values) is airflow.models.connection.Connection
   
               if session.query(Connection).filter(Connection.conn_id == conn_id).first():
                   print(f'Could not import connection {conn_id}: connection already exists.')
                   continue
   
               allowed_fields = [
                   'extra',                                                                                                              
                   'description',
                   'conn_id',
                   'login',                                                                                                                
                   'conn_type',
                   'host',                                                                                                                
                   'password',
                   'schema',
                   'port',
                   'uri',                                                                                                                 
                   'extra_dejson',                                                                                                     
               ]
               filtered_connection_values = {
                   key: value for key, value in conn_values.items() if key in allowed_fields
               }
               connection = _create_connection(conn_id, filtered_connection_values)
               session.add(connection)
               session.commit()
               print(f'Imported connection {conn_id}')      
   ```
   
   I guess in the previous version, method load_connections_dict just loads connections file as a json object. In this situation, this code can run correctly.
   
   Maybe you should use `airflow connections create` for now.
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org