You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "AetherUnbound (via GitHub)" <gi...@apache.org> on 2023/10/05 04:08:54 UTC

[PR] Fix AWS RDS hook's DB instance state check [airflow]

AetherUnbound opened a new pull request, #34773:
URL: https://github.com/apache/airflow/pull/34773

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   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/
   -->
   
   ## Problem
   
   We observed that when the `RdsDbSensor` is run against a database identifier which doesn't yet exist, the sensor fails and enters a retry sequence rather than emitting `False` and poking again at the next interval: https://github.com/WordPress/openverse/issues/2961
   
   The [docs for `get_db_instance_state`](https://airflow.apache.org/docs/apache-airflow-providers-amazon/stable/_api/airflow/providers/amazon/aws/hooks/rds/index.html#airflow.providers.amazon.aws.hooks.rds.RdsHook.get_db_instance_state) say that this should raise `AirflowNotFoundException` if the DB instance doesn't exist, and the [`RdsDbSensor`'s `poke` method](https://airflow.apache.org/docs/apache-airflow-providers-amazon/stable/_modules/airflow/providers/amazon/aws/sensors/rds.html#RdsDbSensor) would seem to comport this with how it's expecting to handle an `AirflowNotFoundException`.
   
   However, when running the hook code locally, the hook instead raises a `DBInstanceNotFoundFault` exception:
   
   ```
   In [5]: response = hook.conn.describe_db_instances(DBInstanceIdentifier='dev-openverse-fake')
   ---------------------------------------------------------------------------
   DBInstanceNotFoundFault                   Traceback (most recent call last)
   Cell In[5], line 1
   ----> 1 response = hook.conn.describe_db_instances(DBInstanceIdentifier='dev-openverse-fake')
   
   File ~/.local/lib/python3.10/site-packages/botocore/client.py:535, in ClientCreator._create_api_method.<locals>._api_call(self, *args, **kwargs)
       531     raise TypeError(
       532         f"{py_operation_name}() only accepts keyword arguments."
       533     )
       534 # The "self" in this scope is referring to the BaseClient.
   --> 535 return self._make_api_call(operation_name, kwargs)
   
   File ~/.local/lib/python3.10/site-packages/botocore/client.py:980, in BaseClient._make_api_call(self, operation_name, api_params)
       978     error_code = parsed_response.get("Error", {}).get("Code")
       979     error_class = self.exceptions.from_code(error_code)
   --> 980     raise error_class(parsed_response, operation_name)
       981 else:
       982     return parsed_response
   
   DBInstanceNotFoundFault: An error occurred (DBInstanceNotFound) when calling the DescribeDBInstances operation: DBInstance dev-openverse-fake not found.
   ```
   
   I tried extracting the error code that is checked here myself:
   
   https://github.com/apache/airflow/blob/0c8e30e43b70e9d033e1686b327eb00aab82479c/airflow/providers/amazon/aws/hooks/rds.py#L229-L246
   
   ```
   In [7]: try:
      ...:     response = hook.conn.describe_db_instances(DBInstanceIdentifier='dev-openverse-fake')
      ...: except hook.conn.exceptions.ClientError as e:
      ...:     x = e
      ...: 
   
   In [8]: x
   Out[8]: botocore.errorfactory.DBInstanceNotFoundFault('An error occurred (DBInstanceNotFound) when calling the DescribeDBInstances operation: DBInstance dev-openverse-fake not found.')
   
   In [10]: x.response
   Out[10]: 
   {'Error': {'Type': 'Sender',
     'Code': 'DBInstanceNotFound',
     'Message': 'DBInstance dev-openverse-fake not found.'},
    'ResponseMetadata': {'RequestId': '[redacted]',
     'HTTPStatusCode': 404,
     'HTTPHeaders': {'x-amzn-requestid': '[redacted]',
      'strict-transport-security': 'max-age=31536000',
      'content-type': 'text/xml',
      'content-length': '289',
      'date': 'Thu, 05 Oct 2023 03:46:28 GMT'},
     'RetryAttempts': 0}}
   ```
   
   It looks like the code that _should_ be checked against is actually `DBInstanceNotFound`, even if the _exception_ is `DBInstanceNotFoundFault`. I've made the change here, there are a few other places in this hook where `DB[issue]Fault` is used where perhaps `DB[issue]` should be used instead. But I wanted to get this PR up with a minimal change at least to get folks' thoughts :slightly_smiling_face:
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ 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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on code in PR #34773:
URL: https://github.com/apache/airflow/pull/34773#discussion_r1347991453


##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   I wonder if we need to check both values since no one reported the issues before.
   ```suggestion
               if e.response["Error"]["Code"] in ["DBInstanceNotFoundFault", "DBInstanceNotFound"]:
   ```
   However if @Taragolis solution is applicable, it would be much better.



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "AetherUnbound (via GitHub)" <gi...@apache.org>.
AetherUnbound commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1792965999

   Crap, GitHub outage is affecting the build steps 😅 Anyone mind re-running them when you have a moment?


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #34773:
URL: https://github.com/apache/airflow/pull/34773#discussion_r1347184383


##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   Better to catch RDS.Client.exceptions.DBInstanceNotFoundFault (as `self.conn.exceptions.DBInstanceNotFoundFault) rather than generic ClientError and parse it.



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "utkarsharma2 (via GitHub)" <gi...@apache.org>.
utkarsharma2 commented on code in PR #34773:
URL: https://github.com/apache/airflow/pull/34773#discussion_r1346888430


##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   @AetherUnbound Thanks for creating the PR :)
   
   Are there any version changes for SDK/Client/API used now vs earlier? 



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #34773:
URL: https://github.com/apache/airflow/pull/34773#discussion_r1347516080


##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   But [boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds/client/describe_db_instances.html) is different from [AWS API reference documentation](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBInstances.html#API_DescribeDBInstances_Errors):
   - Boto3 documentation: `DBInstanceNotFoundFault`
   - API reference documentation: `DBInstanceNotFound`
   
   I trust your testing then and `DBInstanceNotFound` should be the good one 👍 



##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   But [boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds/client/describe_db_instances.html) is different from [AWS API reference documentation](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBInstances.html#API_DescribeDBInstances_Errors):
   - Boto3 documentation: `DBInstanceNotFoundFault`
   - API reference documentation: `DBInstanceNotFound`
   
   I trust your testing then and `DBInstanceNotFound` should be the good one 👍 



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "AetherUnbound (via GitHub)" <gi...@apache.org>.
AetherUnbound commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1793053117

   That's so odd, especially since local testing (shown in the issue description) raises a specific error in some cases 😅 Ah well, I'll change those pieces back.


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #34773:
URL: https://github.com/apache/airflow/pull/34773#discussion_r1347492888


##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   But service exceptions are wrapper into `ClientError`. See [documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html#aws-service-exceptions)



##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   But service exceptions are wrapped into `ClientError`. See [documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html#aws-service-exceptions)



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1749423956

   > If y'all are up for it, I can also change the other `*Fault` string checks to remove the `Fault`, since it's likely those are encountering the same issue. Or we can merge this as-is, either way!
   
   Would be great if you can do it as part of this PR. I'd double check this the correct error code though


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "AetherUnbound (via GitHub)" <gi...@apache.org>.
AetherUnbound commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1792995922

   Weird, it looks like a few tests are failing because they're raising a `ClientError` instead of the actual exception O_o
   
   ```
   FAILED tests/providers/amazon/aws/sensors/test_rds.py::TestRdsExportTaskExistenceSensor::test_export_task_poke_false - botocore.exceptions.ClientError: An error occurred (ExportTaskNotFoundFault) when calling the DescribeExportTasks operation: Cannot cancel export task because a task with the identifier my-db-instance-snap-export is not exist.
   FAILED tests/providers/amazon/aws/hooks/test_rds.py::TestRdsHook::test_get_export_task_state_not_found - botocore.exceptions.ClientError: An error occurred (ExportTaskNotFoundFault) when calling the DescribeExportTasks operation: Cannot cancel export task because a task with the identifier does_not_exist is not exist.
   FAILED tests/providers/amazon/aws/hooks/test_rds.py::TestRdsHook::test_get_event_subscription_state_not_found - botocore.exceptions.ClientError: An error occurred (SubscriptionNotFoundFault) when calling the DescribeEventSubscriptions operation: Subscription does_not_exist not found.
   ```


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1792972591

   I just rebased it. It will re-execute the tests. Though, I am not sure the outage is over


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1793009443

   > Weird, it looks like a few tests are failing because they're raising a `ClientError` instead of the actual exception O_o
   > 
   > ```
   > FAILED tests/providers/amazon/aws/sensors/test_rds.py::TestRdsExportTaskExistenceSensor::test_export_task_poke_false - botocore.exceptions.ClientError: An error occurred (ExportTaskNotFoundFault) when calling the DescribeExportTasks operation: Cannot cancel export task because a task with the identifier my-db-instance-snap-export is not exist.
   > FAILED tests/providers/amazon/aws/hooks/test_rds.py::TestRdsHook::test_get_export_task_state_not_found - botocore.exceptions.ClientError: An error occurred (ExportTaskNotFoundFault) when calling the DescribeExportTasks operation: Cannot cancel export task because a task with the identifier does_not_exist is not exist.
   > FAILED tests/providers/amazon/aws/hooks/test_rds.py::TestRdsHook::test_get_event_subscription_state_not_found - botocore.exceptions.ClientError: An error occurred (SubscriptionNotFoundFault) when calling the DescribeEventSubscriptions operation: Subscription does_not_exist not found.
   > ```
   
   Yes, this is expected from the documentation:
   
   > But service exceptions are wrapped into ClientError. See [documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html#aws-service-exceptions)


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck merged PR #34773:
URL: https://github.com/apache/airflow/pull/34773


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #34773:
URL: https://github.com/apache/airflow/pull/34773#discussion_r1347184383


##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   Better to catch RDS.Client.exceptions.DBInstanceNotFoundFault (as `self.conn.exceptions.DBInstanceNotFoundFault`) rather than generic ClientError and parse it.



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "AetherUnbound (via GitHub)" <gi...@apache.org>.
AetherUnbound commented on code in PR #34773:
URL: https://github.com/apache/airflow/pull/34773#discussion_r1347512062


##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   @vincbeck Right, I mention this in the PR description - the error code itself within the `ClientError` is `DBInstanceNotFound`, but the exception is `DBInstanceNotFoundFault`. I'm all for catching a more specific exception, but the other functions in this file will probably need to be updated as well and I wanted to confirm that was the right way forward before making that change 🙂 
   
   > Are there any version changes for SDK/Client/API used now vs earlier?
   
   Not that I'm aware of, I think this has been an issue since we started using this DAG! Let me take a look at our logs and get back to you though.



##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   @vincbeck Right, I mention this in the PR description - the error code itself within the `ClientError` is `DBInstanceNotFound`, but the exception is `DBInstanceNotFoundFault`. I'm all for catching a more specific exception, but the other functions in this file will probably need to be updated as well and I wanted to confirm that was the right way forward before making that change 🙂 
   
   > Are there any version changes for SDK/Client/API used now vs earlier?
   
   Not that I'm aware of, I think this has been an issue since we started using this DAG! Let me take a look at our logs and get back to you though.



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #34773:
URL: https://github.com/apache/airflow/pull/34773#discussion_r1347505020


##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   But this is weird because from [documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds/client/describe_db_instances.html) it is `DBInstanceNotFoundFault `



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1795210918

   Thanks for the work @AetherUnbound 🥳 


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1793246749

   Yep. Rebased after:
   
   a) we fixed it in main
   b) proposed a PR https://github.com/apache/airflow/pull/35424 that will prevent similar errors to get merged to main in the future
   
   


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "AetherUnbound (via GitHub)" <gi...@apache.org>.
AetherUnbound commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1749366208

   If y'all are up for it, I can also change the other `*Fault` string checks to remove the `Fault`, since it's likely those are encountering the same issue. Or we can merge this as-is, either way!


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "AetherUnbound (via GitHub)" <gi...@apache.org>.
AetherUnbound commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1793189152

   Hmm, that docs build failure seems unrelated 🤔 


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #34773:
URL: https://github.com/apache/airflow/pull/34773#discussion_r1347569893


##########
airflow/providers/amazon/aws/hooks/rds.py:
##########
@@ -240,7 +240,7 @@ def get_db_instance_state(self, db_instance_id: str) -> str:
         try:
             response = self.conn.describe_db_instances(DBInstanceIdentifier=db_instance_id)
         except self.conn.exceptions.ClientError as e:
-            if e.response["Error"]["Code"] == "DBInstanceNotFoundFault":
+            if e.response["Error"]["Code"] == "DBInstanceNotFound":

Review Comment:
   Response Error Code != Exception name
   
   Some simple snippet for play with debugger
   
   ```python
   import boto3
   from botocore.exceptions import ClientError
   
   session = boto3.session.Session(...) # do not forget add creds/profile or set appropriate ENV Vars
   client = session.client("rds")
   
   
   try:
       client.describe_db_instances(DBInstanceIdentifier="foo-bar-spam-egg")
   except client.exceptions.DBInstanceNotFoundFault as ex:
       assert isinstance(ex, ClientError)
       assert isinstance(ex, client.exceptions.ClientError)
       raise
   ```
   
   ![image](https://github.com/apache/airflow/assets/3998685/6391325b-e045-45cf-b100-ac2ffaea535f)
   
   



-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "AetherUnbound (via GitHub)" <gi...@apache.org>.
AetherUnbound commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1755674768

   I haven't forgotten about this, just got busy! It sounds like folks are comfortable with catching specific exceptions instead of checking error codes, which should be more robust in general. I'll modify this PR for all of the RDS functions to make it consistent in that regard.


-- 
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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix AWS RDS hook's DB instance state check [airflow]

Posted by "AetherUnbound (via GitHub)" <gi...@apache.org>.
AetherUnbound commented on PR #34773:
URL: https://github.com/apache/airflow/pull/34773#issuecomment-1792961496

   Interesting note, all of the exception _types_ end in `*Fault`, but I believe the error codes themselves do not:
   
   ```
   In [8]: dir(hook.conn.exceptions)
   Out[8]: 
   ['AuthorizationAlreadyExistsFault',
    'AuthorizationNotFoundFault',
    'AuthorizationQuotaExceededFault',
    'BackupPolicyNotFoundFault',
    'BlueGreenDeploymentAlreadyExistsFault',
    'BlueGreenDeploymentNotFoundFault',
    'CertificateNotFoundFault',
    'ClientError',
    'CreateCustomDBEngineVersionFault',
    'CustomAvailabilityZoneNotFoundFault',
    'CustomDBEngineVersionAlreadyExistsFault',
    'CustomDBEngineVersionNotFoundFault',
    'CustomDBEngineVersionQuotaExceededFault',
    'DBClusterAlreadyExistsFault',
    'DBClusterAutomatedBackupNotFoundFault',
    'DBClusterAutomatedBackupQuotaExceededFault',
    'DBClusterBacktrackNotFoundFault',
    'DBClusterEndpointAlreadyExistsFault',
    'DBClusterEndpointNotFoundFault',
    'DBClusterEndpointQuotaExceededFault',
    'DBClusterNotFoundFault',
    'DBClusterParameterGroupNotFoundFault',
    'DBClusterQuotaExceededFault',
    'DBClusterRoleAlreadyExistsFault',
    'DBClusterRoleNotFoundFault',
    'DBClusterRoleQuotaExceededFault',
    'DBClusterSnapshotAlreadyExistsFault',
    'DBClusterSnapshotNotFoundFault',
    'DBInstanceAlreadyExistsFault',
    'DBInstanceAutomatedBackupNotFoundFault',
    'DBInstanceAutomatedBackupQuotaExceededFault',
    'DBInstanceNotFoundFault',
    'DBInstanceRoleAlreadyExistsFault',
    'DBInstanceRoleNotFoundFault',
    'DBInstanceRoleQuotaExceededFault',
    'DBLogFileNotFoundFault',
    'DBParameterGroupAlreadyExistsFault',
    'DBParameterGroupNotFoundFault',
    'DBParameterGroupQuotaExceededFault',
    'DBProxyAlreadyExistsFault',
    'DBProxyEndpointAlreadyExistsFault',
    'DBProxyEndpointNotFoundFault',
    'DBProxyEndpointQuotaExceededFault',
    'DBProxyNotFoundFault',
    'DBProxyQuotaExceededFault',
    'DBProxyTargetAlreadyRegisteredFault',
    'DBProxyTargetGroupNotFoundFault',
    'DBProxyTargetNotFoundFault',
    'DBSecurityGroupAlreadyExistsFault',
    'DBSecurityGroupNotFoundFault',
    'DBSecurityGroupNotSupportedFault',
    'DBSecurityGroupQuotaExceededFault',
    'DBSnapshotAlreadyExistsFault',
    'DBSnapshotNotFoundFault',
    'DBSubnetGroupAlreadyExistsFault',
    'DBSubnetGroupDoesNotCoverEnoughAZs',
    'DBSubnetGroupNotAllowedFault',
    'DBSubnetGroupNotFoundFault',
    'DBSubnetGroupQuotaExceededFault',
    'DBSubnetQuotaExceededFault',
    'DBUpgradeDependencyFailureFault',
    'DomainNotFoundFault',
    'Ec2ImagePropertiesNotSupportedFault',
    'EventSubscriptionQuotaExceededFault',
    'ExportTaskAlreadyExistsFault',
    'ExportTaskNotFoundFault',
    'GlobalClusterAlreadyExistsFault',
    'GlobalClusterNotFoundFault',
    'GlobalClusterQuotaExceededFault',
    'IamRoleMissingPermissionsFault',
    'IamRoleNotFoundFault',
    'InstanceQuotaExceededFault',
    'InsufficientAvailableIPsInSubnetFault',
    'InsufficientDBClusterCapacityFault',
    'InsufficientDBInstanceCapacityFault',
    'InsufficientStorageClusterCapacityFault',
    'InvalidBlueGreenDeploymentStateFault',
    'InvalidCustomDBEngineVersionStateFault',
    'InvalidDBClusterAutomatedBackupStateFault',
    'InvalidDBClusterCapacityFault',
    'InvalidDBClusterEndpointStateFault',
    'InvalidDBClusterSnapshotStateFault',
    'InvalidDBClusterStateFault',
    'InvalidDBInstanceAutomatedBackupStateFault',
    'InvalidDBInstanceStateFault',
    'InvalidDBParameterGroupStateFault',
    'InvalidDBProxyEndpointStateFault',
    'InvalidDBProxyStateFault',
    'InvalidDBSecurityGroupStateFault',
    'InvalidDBSnapshotStateFault',
    'InvalidDBSubnetGroupFault',
    'InvalidDBSubnetGroupStateFault',
    'InvalidDBSubnetStateFault',
    'InvalidEventSubscriptionStateFault',
    'InvalidExportOnlyFault',
    'InvalidExportSourceStateFault',
    'InvalidExportTaskStateFault',
    'InvalidGlobalClusterStateFault',
    'InvalidOptionGroupStateFault',
    'InvalidRestoreFault',
    'InvalidS3BucketFault',
    'InvalidSubnet',
    'InvalidVPCNetworkStateFault',
    'KMSKeyNotAccessibleFault',
    'NetworkTypeNotSupported',
    'OptionGroupAlreadyExistsFault',
    'OptionGroupNotFoundFault',
    'OptionGroupQuotaExceededFault',
    'PointInTimeRestoreNotEnabledFault',
    'ProvisionedIopsNotAvailableInAZFault',
    'ReservedDBInstanceAlreadyExistsFault',
    'ReservedDBInstanceNotFoundFault',
    'ReservedDBInstanceQuotaExceededFault',
    'ReservedDBInstancesOfferingNotFoundFault',
    'ResourceNotFoundFault',
    'SNSInvalidTopicFault',
    'SNSNoAuthorizationFault',
    'SNSTopicArnNotFoundFault',
    'SharedSnapshotQuotaExceededFault',
    'SnapshotQuotaExceededFault',
    'SourceClusterNotSupportedFault',
    'SourceDatabaseNotSupportedFault',
    'SourceNotFoundFault',
    'StorageQuotaExceededFault',
    'StorageTypeNotAvailableFault',
    'StorageTypeNotSupportedFault',
    'SubnetAlreadyInUse',
    'SubscriptionAlreadyExistFault',
    'SubscriptionCategoryNotFoundFault',
    'SubscriptionNotFoundFault',
   ```
   
   Going to go ahead and change all the logic over!


-- 
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: commits-unsubscribe@airflow.apache.org

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