sunank200 opened a new pull request, #31567: URL: https://github.com/apache/airflow/pull/31567
<!-- Thank you for contributing! Please make sure that your code changes are covered with tests. And in case of new features or big changes remember to adjust the documentation. Feel free to ping committers for the review! In case of an existing issue, reference it using one of the following: closes: #ISSUE related: #ISSUE How to write a good git commit message: http://chris.beams.io/posts/git-commit/ --> This is a bug in the current implementation as per the [PR](https://github.com/apache/airflow/pull/28187). When user passes the following as part of redshift connection, it would break: ``` { "iam": true, "cluster_identifier": "redshift-cluster-1", "port": 5439, "region": "us-east-1", "db_user": "awsuser", "database": "dev", "profile": "default" } ``` The following image shows that the `host` is not set in the connection but `cluster_identifier` is set.  Even though the `cluster_identifier` is set here this would break with the following error on the [line](https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/hooks/redshift_sql.py#L107) as host is not set because `conn.host` is evaluated first and when we split it to `NoneType` object it would throw attribute error. ``` conn.extra_dejson.get("cluster_identifier", conn.host.split(".")[0]) ```  Following is the test we did. ``` >>> conn.extra_dejson.get("cluster_identifier") PyDev console: starting. '<REDSHIFT_CLUSTER_IDENTIFIER>' >>> conn.extra_dejson.get("cluster_identifier", None) '<REDSHIFT_CLUSTER_IDENTIFIER>' >>> conn.host >>> conn.extra_dejson.get("cluster_identifier", conn.host.split(".")[0]) Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec exec(exp, global_vars, local_vars) File "<input>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'split' ``` This is a bug in the current implementation for all users when `host` is not set in the [connection](https://airflow.apache.org/docs/apache-airflow-providers-amazon/stable/connections/redshift.html) (not only for default connections). This would require a null check for `conn.host`. closes: #31551 Added a null check for `conn.host`. `conn.host.split(".")[0]` is compiled regardless of the extra values. --- **^ Add meaningful description above** Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information. In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed. In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x). In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments). -- 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]
