airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Extra in Connections __init__

Open nave91 opened this issue 11 years ago • 2 comments

I am trying to write a plugin that encapsulates all of my connections. I had no trouble working with PostgresHook which I extended in my plugin to have connection information ready to use(from env variables). But when I use S3Hook, it seems like I cannot create a connection using function create_connection as:


class DevS3Hook(S3Hook):
    ...
    def create_connection(self):
        session = sessionmaker(bind=engine)()
        conn_ids = [s.conn_id for s in session.query(Connection)]
        if not self.DEV_S3_CONN_ID in conn_ids:
            self.extra_params = str({
                'aws_access_key_id': self.DEV_AWS_KEY,
                'aws_secret_access_key': self.DEV_AWS_PASS
            })
            conn = Connection(
                conn_id=self.DEV_S3_CONN_ID,
                conn_type=self.DEV_S3_CONN_TYPE,
                extra=self.extra_params
            )
            session.add(conn)
            session.commit()

Note: All variables in capital are initialized in init of DevS3Hook

It gives the following error:

In [4]: h = hooks.DevS3Hook()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-74f3fbe7da94> in <module>()
----> 1 h = hooks.DevS3Hook()

<scrubbed_path> in __init__(self, *args, **kwargs)
    116         self.default_conn_name = self.DEV_S3_CONN_ID
    117 
--> 118         self.create_connection()
    119         super(DevS3Hook, self).__init__(*args, **kwargs)
    120 

<scrubbed_path> in create_connection(self)
    130                 conn_id=self.DEV_S3_CONN_ID,
    131                 conn_type=self.DEV_S3_CONN_TYPE,
--> 132                 extra=self.extra_params
    133             )
    134             session.add(conn)

TypeError: __init__() got an unexpected keyword argument 'extra'

Is there any specific reason extra is not included in init of Connection?

nave91 avatar Aug 18 '15 21:08 nave91

This can actually solve my problem.

nave91 avatar Aug 18 '15 21:08 nave91

I just pulled your simple commit in master, there are no good reasons why it wasn't in there....

mistercrunch avatar Aug 19 '15 00:08 mistercrunch