Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

feat: accept TableListItem where TableReference is accepted - #1016

Merged
gcf-merge-on-green[bot] merged 9 commits into
googleapis:mainfrom
steffnay:accept-TLI
Nov 1, 2021
Merged

feat: accept TableListItem where TableReference is accepted#1016
gcf-merge-on-green[bot] merged 9 commits into
googleapis:mainfrom
steffnay:accept-TLI

Conversation

@steffnay

Copy link
Copy Markdown
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • 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
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

🦕

@steffnay
steffnay requested review from a team and shollymanOctober 11, 2021 21:46
@product-auto-labelproduct-auto-labelBot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Oct 11, 2021
@google-clagoogle-claBot added the cla: yes This human has signed the Contributor License Agreement. label Oct 11, 2021
@tswast

Copy link
Copy Markdown
Contributor

Looks like we need to either update the test_get_iam_policy_w_invalid_table test to look for ValueError or update _parse_3_part_id to raise TypeError.

Based on https://docs.python.org/3/library/exceptions.html#TypeError, I think ValueError is more accurate.

________________ TestClient.test_get_iam_policy_w_invalid_table ________________
self = <tests.unit.test_client.TestClient testMethod=test_get_iam_policy_w_invalid_table>
def test_get_iam_policy_w_invalid_table(self):
creds = _make_credentials()
http = object()
client = self._make_one(project=self.PROJECT, credentials=creds, _http=http)
table_resource_string = "projects/{}/datasets/{}/tables/{}".format(
self.PROJECT, self.DS_ID, self.TABLE_ID,
)
with self.assertRaises(TypeError):
> client.get_iam_policy(table_resource_string)
tests/unit/test_client.py:1558:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
google/cloud/bigquery/client.py:813: in get_iam_policy
table = _table_arg_to_table_ref(table, default_project=self.project)
google/cloud/bigquery/table.py:2666: in _table_arg_to_table_ref
value = TableReference.from_string(value, default_project=default_project)
google/cloud/bigquery/table.py:252: in from_string
) = _helpers._parse_3_part_id(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def _parse_3_part_id(full_id, default_project=None, property_name="table_id"):
output_project_id = default_project
output_dataset_id = None
output_resource_id = None
parts = _split_id(full_id)
if len(parts) != 2 and len(parts) != 3:
> raise ValueError(
"{property_name} must be a fully-qualified ID in "
'standard SQL format, e.g., "project.dataset.{property_name}", '
"got {}".format(full_id, property_name=property_name)
)
E ValueError: table_id must be a fully-qualified ID in standard SQL format, e.g., "project.dataset.table_id", got projects/PROJECT/datasets/DATASET_ID/tables/TABLE_ID
google/cloud/bigquery/_helpers.py:848: ValueError

Comment threadgoogle/cloud/bigquery/client.py Outdated
raise TypeError("table must be a Table or TableReference")
table = _table_arg_to_table_ref(table, default_project=self.project)
if not isinstance(table, (TableReference)):
raise TypeError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need unit test that covers this. Possibly this if statement can be deleted if _table_arg_to_table_ref already throws?

Comment threadgoogle/cloud/bigquery/client.py Outdated
raise TypeError("table must be a Table or TableReference")
table = _table_arg_to_table_ref(table, default_project=self.project)
if not isinstance(table, (TableReference)):
raise TypeError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Line not covered in unit tests

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Ah, got it! Thanks!

Comment threadgoogle/cloud/bigquery/client.py Outdated
raise TypeError("table must be a Table or TableReference")
table = _table_arg_to_table_ref(table, default_project=self.project)
if not isinstance(table, (TableReference)):
raise TypeError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Line not covered in unit tests

@steffnay
steffnay requested a review from tswastOctober 26, 2021 19:49
@tswasttswast added the automerge Merge the pull request once unit tests and other checks pass. label Nov 1, 2021
@gcf-merge-on-green
gcf-merge-on-greenBot merged commit fe16adc into googleapis:mainNov 1, 2021
@gcf-merge-on-greengcf-merge-on-greenBot removed the automerge Merge the pull request once unit tests and other checks pass. label Nov 1, 2021
abdelmegahedgoogle pushed a commit to abdelmegahedgoogle/python-bigquery that referenced this pull request Apr 17, 2023
…is#1016)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery/issues/new/choose) 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
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
🦕
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@steffnay@tswast