RamiNoodle733 opened a new pull request, #61510:
URL: https://github.com/apache/airflow/pull/61510
# Pull Request: Remove redundant try/except blocks in Bigtable operators
## Related Issue
Fixes #60687
## Description
This PR removes unnecessary exception handling in Bigtable operators where
try/except blocks were catching `GoogleAPICallError`, logging a generic error
message, and then immediately re-raising the exception.
### Why this change is needed:
1. **Redundant pattern**: The try/except blocks were catching exceptions
only to log a generic message and re-raise them:
```python
except google.api_core.exceptions.GoogleAPICallError as e:
self.log.error("An error occurred. Exiting.")
raise e
```
This pattern adds no value since:
- The Hook methods already let exceptions bubble up naturally
- The generic error message provides no additional context
- The exception stack trace is preserved either way
2. **Follows Airflow architecture**: In Airflow's design pattern:
- **Hooks** handle API interactions and error handling
- **Operators** focus on orchestration and business logic
When Hooks already handle specific error cases gracefully (like
`BigtableHook.delete_instance()` handling `NotFound`), Operators shouldn't
duplicate this logic.
3. **Code quality**: Removing these redundant blocks:
- Reduces code nesting and improves readability
- Eliminates duplicate error handling logic
- Makes the code cleaner and more maintainable
## Changes Made
| Operator | Change |
|----------|--------|
| `BigtableCreateInstanceOperator` | Removed try/except `GoogleAPICallError`
|
| `BigtableUpdateInstanceOperator` | Removed try/except `GoogleAPICallError`
|
| `BigtableDeleteTableOperator` | Removed redundant `GoogleAPICallError`
handler (kept `NotFound` handler for idempotent delete behavior) |
| `BigtableUpdateClusterOperator` | Removed redundant `GoogleAPICallError`
handler (kept `NotFound` handler for custom error message) |
## Behavioral Changes
**No behavioral changes.** Exceptions will still propagate correctly - they
just won't be caught and immediately re-raised anymore.
### Exceptions intentionally kept:
- `BigtableDeleteTableOperator`: Keeps `NotFound` handler to make deletes
idempotent (if table doesn't exist, log and continue)
- `BigtableUpdateClusterOperator`: Keeps `NotFound` handler to provide a
custom, informative error message
- `BigtableCreateTableOperator`: Already had proper handling for
`AlreadyExists` with validation logic
## Testing
- [x] Verified Python syntax is valid
- [x] Verified no redundant `GoogleAPICallError` handlers remain
- [x] Existing tests should continue to pass (they test that exceptions
propagate, which they still do)
## Checklist
- [x] Code follows the project's style guidelines
- [x] Self-review of code completed
- [x] Code changes are focused and minimal
- [x] No breaking changes introduced
---
**For Data Engineering Resume:**
This contribution demonstrates:
- Understanding of Airflow's Operator/Hook architecture
- Code refactoring for improved maintainability
- Working with Google Cloud Bigtable (NoSQL database)
- Open source contribution workflow
--
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]