Skip to content

chore: Fallback to inputs if impersonation fails#52052

Merged
tomasfarias merged 2 commits intomasterfrom
chore/fallback-to-inputs-when-impersonation-fails
Mar 24, 2026
Merged

chore: Fallback to inputs if impersonation fails#52052
tomasfarias merged 2 commits intomasterfrom
chore/fallback-to-inputs-when-impersonation-fails

Conversation

@tomasfarias
Copy link
Contributor

Problem

Migrating everyone to new integration is scary, let's make it safer.

Changes

If using the new methods fails, fallback to using inputs.
Also re-ordered things a bit in the integration model, but no actual changes.

How did you test this code?

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Publish to changelog?

Docs update

Comment on lines +1200 to +1208
sensitive_config = {}
is_impersonated = True
if isinstance(private_key, str) and isinstance(private_key_id, str) and isinstance(token_uri, str):
sensitive_config["private_key"] = private_key
sensitive_config["private_key_id"] = private_key_id
sensitive_config["token_uri"] = token_uri

is_impersonated = False

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this is closer to where is_impersonated is used

Comment on lines +1352 to +1353
# We cannot fallback to using inputs
raise
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case when impersonation is required: i.e. new batch exports using impersonation. Everyone else has inputs.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 24, 2026

Prompt To Fix All With AI
This is a comment left during a code review.
Path: products/batch_exports/backend/temporal/destinations/bigquery_batch_export.py
Line: 1343-1344

Comment:
**ERROR-level log fires even when fallback succeeds**

`LOGGER.exception(...)` logs at ERROR level and includes the full exception traceback. When the fallback to `from_service_account_inputs` succeeds, the operation completes successfully — but the ERROR log (and any associated alert) still fires. This creates noisy false-positive errors in monitoring dashboards.

Consider logging at WARNING before trying the fallback, and only escalate to ERROR if the fallback also fails:

```python
            except Exception:
                LOGGER.warning("Initialize client from service account integration failed, falling back to inputs", exc_info=True)
                # TODO: Migrate everyone and remove this
                if (
                    inputs.private_key is None
                    or inputs.private_key_id is None
                    or inputs.token_uri is None
                    or inputs.client_email is None
                ):
                    # We cannot fallback to using inputs
                    LOGGER.exception("Cannot fall back: missing required inputs")
                    raise
                bq_client = BigQueryClient.from_service_account_inputs(
                    inputs.private_key, inputs.private_key_id, inputs.token_uri, inputs.client_email, project_id
                )
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "chore: Re-order statements a bit" | Re-trigger Greptile

Comment on lines +1343 to +1344
except Exception:
LOGGER.exception("Initialize client from service account failed")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 ERROR-level log fires even when fallback succeeds

LOGGER.exception(...) logs at ERROR level and includes the full exception traceback. When the fallback to from_service_account_inputs succeeds, the operation completes successfully — but the ERROR log (and any associated alert) still fires. This creates noisy false-positive errors in monitoring dashboards.

Consider logging at WARNING before trying the fallback, and only escalate to ERROR if the fallback also fails:

            except Exception:
                LOGGER.warning("Initialize client from service account integration failed, falling back to inputs", exc_info=True)
                # TODO: Migrate everyone and remove this
                if (
                    inputs.private_key is None
                    or inputs.private_key_id is None
                    or inputs.token_uri is None
                    or inputs.client_email is None
                ):
                    # We cannot fallback to using inputs
                    LOGGER.exception("Cannot fall back: missing required inputs")
                    raise
                bq_client = BigQueryClient.from_service_account_inputs(
                    inputs.private_key, inputs.private_key_id, inputs.token_uri, inputs.client_email, project_id
                )
Prompt To Fix With AI
This is a comment left during a code review.
Path: products/batch_exports/backend/temporal/destinations/bigquery_batch_export.py
Line: 1343-1344

Comment:
**ERROR-level log fires even when fallback succeeds**

`LOGGER.exception(...)` logs at ERROR level and includes the full exception traceback. When the fallback to `from_service_account_inputs` succeeds, the operation completes successfully — but the ERROR log (and any associated alert) still fires. This creates noisy false-positive errors in monitoring dashboards.

Consider logging at WARNING before trying the fallback, and only escalate to ERROR if the fallback also fails:

```python
            except Exception:
                LOGGER.warning("Initialize client from service account integration failed, falling back to inputs", exc_info=True)
                # TODO: Migrate everyone and remove this
                if (
                    inputs.private_key is None
                    or inputs.private_key_id is None
                    or inputs.token_uri is None
                    or inputs.client_email is None
                ):
                    # We cannot fallback to using inputs
                    LOGGER.exception("Cannot fall back: missing required inputs")
                    raise
                bq_client = BigQueryClient.from_service_account_inputs(
                    inputs.private_key, inputs.private_key_id, inputs.token_uri, inputs.client_email, project_id
                )
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not a false positive: failure is not expected we want to be alerted. The fallback is there to make things safer, not because it is part of the expected path. The "TODO: Remove this" comment should have made this obvious.

@tomasfarias tomasfarias requested a review from a team March 24, 2026 10:23
@tomasfarias tomasfarias merged commit eeee7bb into master Mar 24, 2026
218 checks passed
@tomasfarias tomasfarias deleted the chore/fallback-to-inputs-when-impersonation-fails branch March 24, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants