Skip to content

Remove redundant try/except blocks in airflow/providers/google/cloud/operators/bigtable.py #60687

Description

@KamranImaaz

Apache Airflow Provider(s)

google

Versions of Apache Airflow Providers

No response

Apache Airflow version

3.2.0

Operating System

Windows(Local Development)

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

What happened

In The Operator Bigtable.py contains several try/except block that are not required and not expected in Operator Level as it Should be handled at Hook Level.

Moreover The Exceptions raised at the Operator level are already Handled at the Hook Level. So what's the point of duplicating it in Operator Level. Let me take an example here

Bigtable.py operator file contains one class BigtableDeleteInstanceOperator which has a method

`    def execute(self, context: Context) -> None:
        hook = BigtableHook(
            gcp_conn_id=self.gcp_conn_id,
            impersonation_chain=self.impersonation_chain,
        )
        try:
            hook.delete_instance(project_id=self.project_id, instance_id=self.instance_id)
        except google.api_core.exceptions.NotFound:
            self.log.info(
                "The instance '%s' does not exist in project '%s'. Consider it as deleted",
                self.instance_id,
                self.project_id,
            )
        except google.api_core.exceptions.GoogleAPICallError as e:
            self.log.error("An error occurred. Exiting.")
            raise e`

It raises exception when the instance does not exists which is already handled at the Hook level see below

`    @GoogleBaseHook.fallback_to_default_project_id
    def delete_instance(self, instance_id: str, project_id: str) -> None:

        instance = self.get_instance(instance_id=instance_id, project_id=project_id)
        if instance:
            instance.delete()
        else:
            self.log.warning(
                "The instance '%s' does not exist in project '%s'. Exiting", instance_id, project_id
            )`

Like wise the whole Bigquery.py has lot's of not necessary try/except blocks.

What you think should happen instead

No response

How to reproduce

I will raise a PR for the above mentioned code first and in the next PR I will fix the whole Bigtable.py file.

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Jan 17, 2026
  2. KamranImaaz commented on Jan 17, 2026

    @KamranImaaz
    ContributorAuthor

    If it's fine I will raise a PR to fix the above code and in the next PR I will fix the whole Bigtable.py file. waiting for your approval :)

  3. added
    provider:google
    on Jan 17, 2026
  4. KamranImaaz commented on Jan 17, 2026

    @KamranImaaz
    ContributorAuthor

    @shahar1 can you pls look into this once

  5. removed
    needs-triage
    on Jan 17, 2026
  6. shahar1 commented on Jan 17, 2026

    @shahar1
    Contributor

    Seems like a good catch - we've carried these duplications for over 7 years, and we could definitely optimize them.
    I'll assign you to this task. Important notes before implementing

    1. Make sure that existing behavior in the operator persists, specifically the idempotency of the Delete operators (please read therad).
    2. Make sure to update unit tests.
    3. I suggest to create separate PR for each file (bigquery, bigtable), because they're...well, big (pun intended) :)
  7. KamranImaaz commented on Jan 17, 2026

    @KamranImaaz
    ContributorAuthor

    Sure I'll follow this

  8. KamranImaaz commented on Jan 17, 2026

    @KamranImaaz
    ContributorAuthor

    Can you pls assign it to me just in case to avoid duplicacy. I will start working on this

  9. shahar1 commented on Jan 17, 2026

    @shahar1
    Contributor

    Can you pls assign it to me just in case to avoid duplicacy. I will start working on this

    I thought I did, my bad - you're officially assigned :)

  10. KamranImaaz commented on Jan 17, 2026

    @KamranImaaz
    ContributorAuthor

    Thanks I'll start working

  11. shahar1 commented on Jan 18, 2026

    @shahar1
    Contributor

    The issue seems to be applied only on "Delete Instance Operator", not the "Delete Table"

  12. Shrivadhu commented on Jan 19, 2026

    @Shrivadhu

    Hi @shahar1, @KamranImaaz 👋

    I noticed this issue is currently assigned, but I’d love to contribute as well.
    I can work specifically on:

    • extending the fix to BigtableDeleteTableOperator, or
    • adding/updating unit tests to ensure idempotency

    Please let me know if that would be helpful, and I’ll proceed accordingly.
    Thanks!

  13. shahar1 commented on Jan 19, 2026

    @shahar1
    Contributor

    Hi @shahar1, @KamranImaaz 👋

    I noticed this issue is currently assigned, but I’d love to contribute as well.
    I can work specifically on:

    • extending the fix to BigtableDeleteTableOperator, or
    • adding/updating unit tests to ensure idempotency

    Please let me know if that would be helpful, and I’ll proceed accordingly.
    Thanks!

    Hey there! I appreciate your will to contribute - but I think that currently there's no need for more people to work on this issue.
    Please explore other unassigned issues labeled as good first issue, or such issues that have been stale for a while - you may tag me and I'll happily assign you.

  14. SeifEddineMezned commented on Jan 20, 2026

    @SeifEddineMezned

    Hi,I opened a PR to address this issue: #60825
    It removes redundant try/except blocks in Bigtable operators while keeping behavior-changing handlers intact.

  15. KamranImaaz commented on Jan 20, 2026

    @KamranImaaz
    ContributorAuthor

    Hi,I opened a PR to address this issue: #60825 It removes redundant try/except blocks in Bigtable operators while keeping behavior-changing handlers intact.

    Please read the issue and comments thoroughly. As this issue is already addressed. Please look for other issues.

  16. shahar1 commented on Jan 20, 2026

    @shahar1
    Contributor

    Hi,I opened a PR to address this issue: #60825 It removes redundant try/except blocks in Bigtable operators while keeping behavior-changing handlers intact.

    Please read my comment in the PR and my comment below.

    Hi,I opened a PR to address this issue: #60825 It removes redundant try/except blocks in Bigtable operators while keeping behavior-changing handlers intact.

    Please read the issue and comments thoroughly. As this issue is already addressed. Please look for other issues.

    Please let me handle the situation.
    As long as you stay active, I'll give you the opportunity to take care of all try..except in this file.


    For new contributors who consider to step in - this issue is currently assigned and there are 106 other unassigned issues labeled as good first issue. Please do not create PRs for this issue and try them instead, that is unless either @KamranImaaz agrees for that, or he becomes inactive for at least a week. Thank you.

  17. shahar1 commented on Jan 24, 2026

    @shahar1
    Contributor

    @KamranImaaz Would you like to handle the other redundant try...except expressions in this file?

  18. KamranImaaz commented on Jan 24, 2026

    @KamranImaaz
    ContributorAuthor

    Yes I would like to work on it

  19. KamranImaaz commented on Jan 24, 2026

    @KamranImaaz
    ContributorAuthor

    I will raise a PR for it soon.

  20. Tanmay-Ts commented on Jan 29, 2026

    @Tanmay-Ts

    I confirm this issue

  21. Tanmay-Ts commented on Jan 29, 2026

    @Tanmay-Ts

    Thanks for the update and the linked PR.
    I’m happy to help with any follow-up or additional cleanup if needed. Please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:providersgood first issuekind:bugprovider:google

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions