KimchaC opened a new issue #10783:
URL: https://github.com/apache/airflow/issues/10783


   The MsSqlOperator included in 1.10.* is using MsSqlHook, which is using 
pymssql. But pymssql has been discontinued and has some nasty, unfixed bugs.
   
   Airflow 2.0 has deprecated MsSqlHook in favor of OdbcHook, which is using 
pyodbc.
   
   But the MsSqlOperator still allows the user to choose, whether MsSqlHook or 
OdbcHook is used. This is done by checking the conn_type of the connection. If 
it is set to "odbc", then ObdcHook is used, otherwise MsSqlHook is used.
   
   The right hook is selected through `Connection.get_hook()`.
   
   Unfortunately, Airflow 1.10 doesn't have an odbc conn_type. You can't select 
it in the UI and there is no logic to select OdbcHook in 
`Connection.get_hook()`.
   
   So the mssql backport is basically unusable as it provides no benefit 
compared to the standard 1.10 mssql module.
   
   At the moment I would suggest to change the selection logic to select 
MsSqlHook if the conn_type is `mssql` and otherwise default to odbc.
   
   Here's how it could be implemented:
   ```python
       def get_hook(self):
           """
           Will retrieve hook as determined by Connection.
   
           If conn_type is ``'mssql'``, will use
           :py:class:`~airflow.providers.microsoft.mssql.hooks.mssql.MsSqlHook`.
           Otherwise, :py:class:`~airflow.providers.odbc.hooks.odbc.OdbcHook` 
will be used.
           """
           if not self._hook:
               conn = MsSqlHook.get_connection(conn_id=self.mssql_conn_id)
   
               if conn.conn_type == 'mssql':
                   self._hook = MsSqlHook(mssql_conn_id=self.mssql_conn_id,
                                          schema=self.database)
               else:
                   self._hook = OdbcHook(odbc_conn_id=self.mssql_conn_id,
                                         database=self.database)
   
           return self._hook
   ```
   
   Long-term, I think it would make a lot of sense to allow plugins to add 
custom connection types to avoid this kind of issue.
   


----------------------------------------------------------------
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:
[email protected]


Reply via email to