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: Fix metadata reflection without a default dataset #1089

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JacobHayes
Copy link
Contributor

@JacobHayes JacobHayes commented Jun 27, 2024

Fixes #838 and fixes #1088. 🦕

The get_table_names and get_view_names methods are supposed to return the bare names (no {schema}. prefix) of the resources for a single schema/dataset (where schema=None is the "default schema", not "all schemas"). However, the BigQueryDialect implementation returns:

  • bare names for a specific schema: if the connection has a default dataset
  • {schema}. prefixed names for one schema: if the connection doesn't have a default dataset and the schema arg is a string
  • {schema}. prefixed names for all schemas: if the connection doesn't have a default dataset and the schema arg is None

The bolded parts cause issues outlined in #1088. This PR fixes the get_table_names and get_view_names implementations to return bare names as SQLAlchemy expects.

This is a breaking change for a subset of users:

  • (no impact) connections with a default dataset (likely a majority of users?) should behave the same
  • (impact) connections without a default dataset using Metadata.reflect() without a schema argument were probably expecting to reflect all datasets, but they would now not reflect anything.
    • BigQuery doesn't have the same concept of a default schema the way eg: PostgreSQL does (public) - so without a default set on the connection string, we don't have anything to search and return an empty list.
  • (no impact) connections without a default dataset using Alembic were probably broken anyway

This has been working for me locally with alembic + no default dataset (the models specify the schema) + include_schemas=True (required for cross-schema stuff).


  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
    • unit tests + linter pass locally
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. labels Jun 27, 2024
Copy link

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@JacobHayes JacobHayes force-pushed the fix-table-reflection branch 2 times, most recently from 969685f to 4a006bf Compare June 27, 2024 07:06
@JacobHayes JacobHayes marked this pull request as ready for review June 27, 2024 07:12
@JacobHayes JacobHayes requested review from a team as code owners June 27, 2024 07:12
@JacobHayes JacobHayes changed the title Fix get_table_names and get_view_names without a default dataset Fix metadata reflection without a default dataset Jul 2, 2024
@JacobHayes JacobHayes changed the title Fix metadata reflection without a default dataset fix: Fix metadata reflection without a default dataset Jul 18, 2024
@JacobHayes
Copy link
Contributor Author

Hi, any chance I could get the tests approved to run on the PR? I've been trying to setup the system tests locally, but they're a bit onerous (understandably).

@Linchin Linchin added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 22, 2024
@Linchin
Copy link
Contributor

Linchin commented Jul 22, 2024

Sorry for the delay, just started running the tests!

@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 22, 2024
@JacobHayes
Copy link
Contributor Author

Sorry for the delay, just started running the tests!

no worries, thank you!

@Linchin Linchin added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Jul 23, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 23, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 23, 2024
@chalmerlowe
Copy link
Collaborator

@lingchin if this is a breaking change as Jacob indicates, then we need to have some sort of deprecation warning that the break is coming and get this into the schedule.

This is a breaking change for a subset of users:

  • (no impact) connections with a default dataset (likely a majority of users?) should behave the same
  • (impact) connections without a default dataset using Metadata.reflect() without a schema argument were probably expecting to reflect all datasets, but they would now not reflect anything. BigQuery doesn't have the same concept of a default schema the way eg: PostgreSQL does (public) - so without a default set on the connection string, we don't have anything to search and return an empty list.
  • (no impact) connections without a default dataset using Alembic were probably broken anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. size: m Pull request size is medium.
Projects
None yet
4 participants