Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(batch-exports): Try to handle missing Postgres permissions #27437

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

rossgray
Copy link
Contributor

Problem

We try to fetch a list of columns for the destination table in case it doesn't contain all the columns present in the record batch. However this can sometimes fail with permissions errors if we don't have SELECT permissions on the destination table.

Changes

Catch permissions errors and assume all columns are present. Note that this means existing batch exports could still fail during the merge if the destination table is missing columns present in the record batch.

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

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Existing tests

@rossgray rossgray requested a review from tomasfarias January 10, 2025 13:20
Comment on lines 683 to 687
await internal_logger.awarning(
"Insufficient privileges to get table columns for table '%s.%s'; will assume all columns are present",
schema=inputs.schema,
table_name=inputs.table_name,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably make this a public log if we indicate users how to resolve this:

  • Grant us permissions.
  • Ensure table is updated to latest schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's a good idea, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have updated

Comment on lines 684 to 685
schema=inputs.schema,
table_name=inputs.table_name,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't these two be positional parameters if we are using the formatting %s?

Copy link
Contributor

Choose a reason for hiding this comment

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

>>> logger.info("%s.%s", schema="test", table="test")
2025-01-10 14:33:10 [info     ] %s.%s                          schema=test table=test
>>> logger.info("%s.%s", "test", "test")
2025-01-10 14:33:21 [info     ] test.test

I assume we expect the second result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yes, sorry, my bad

"Insufficient privileges to get table columns for table '%s.%s'; "
"will assume all columns are present. If this results in an error, please grant SELECT "
"permissions on this table or ensure the destination table is using the latest schema "
"as described in the docs.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we link the docs here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, have added now 👍

@rossgray rossgray requested a review from tomasfarias January 10, 2025 13:51
Copy link
Contributor

@tomasfarias tomasfarias left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you!

@rossgray rossgray enabled auto-merge (squash) January 10, 2025 13:55
@rossgray rossgray merged commit caacec4 into master Jan 10, 2025
92 checks passed
@rossgray rossgray deleted the postgres-handle-missing-permissions branch January 10, 2025 14:55
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