alexbegg opened a new issue #19506:
URL: https://github.com/apache/airflow/issues/19506


   ### Apache Airflow Provider(s)
   
   salesforce
   
   ### Versions of Apache Airflow Providers
   
   apache-airflow-providers-salesforce==1!3.2.0
   
   ### Apache Airflow version
   
   2.1.4
   
   ### Operating System
   
   Debian GNU/Linux 10 (buster)
   
   ### Deployment
   
   Astronomer
   
   ### Deployment details
   
   _No response_
   
   ### What happened
   
   Right now the `SalesforceHook` is requiring all of the extras for a 
Salesforce connection type in Airflow.
   
   I am assuming this issue was never brought up before because users of this 
hook have been using the Airflow UI to make connections (which presents all 
extra fields), however with things such as Secrets Backends, it should be 
possible to set up a Salesforce connection URI without having to explicitly 
provide all of the extras.
   
   The issue is the hook's author designed the hook's `get_conn` to pass in 
every extra value using an improper/invalid method of defaulting to None by 
using `or None` but still referencing the extras key directly. I tested this in 
as low as Python 2.7 and as high as Python 3.7 and in both versions if any one 
of these extras are not provided you will get a `KeyError`
   
   
https://github.com/apache/airflow/blob/e9a72a4e95e6d23bae010ad92499cd7b06d50037/airflow/providers/salesforce/hooks/salesforce.py#L137-L149
   
   ### What you expected to happen
   
   Any extras value not provided will just default to None (or to 
`api.DEFAULT_API_VERSION` for the "version" extra). It should be possible to 
set up a Salesforce connection URI using a secrets backend without having to 
explicitly provide all of the extras.
   
   ### How to reproduce
   
   Set up a secrets backend (such as via environment variable) and pass in the 
minimum connection values needed for "Password" connection type:
   
   _(this is an example, no real passwords shown)_
   `export 
AIRFLOW_CONN_SALESFORCE_DEFAULT='http://your_username:your_password@https%3A%2F%2Fyour_host.lightning.force.com?extra__salesforce__security_token=your_token'`
   
   It will error with `KeyError: 'extra__salesforce__domain'` and keep 
resulting in key errors for each extras key until you finally provide all 
extras, like so:
   
   _(this is an example, no real passwords shown)_
   `export 
AIRFLOW_CONN_SALESFORCE_DEFAULT='http://your_username:your_password@https%3A%2F%2Fyour_host.lightning.force.com?extra__salesforce__security_token=your_token&extra__salesforce__domain=&extra__salesforce__instance=&extra__salesforce__instance_url=&extra__salesforce__organization_id=&extra__salesforce__version=&extra__salesforce__proxies=&extra__salesforce__client_id=Aiflow&extra__salesforce__consumer_key=&extra__salesforce__private_key_file_path=&extra__salesforce__private_key='`
   
   ### Anything else
   
   In addition to this, the `SalesforceHook` should also accept extras without 
the need for the `extra__salesforce__` prefix, like many other connections do.
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


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