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

feat: accept TableListItem where TableReference is accepted #1016

Merged
merged 9 commits into from
Nov 1, 2021

Conversation

steffnay
Copy link
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 a review from a team October 11, 2021 21:46
@steffnay steffnay requested a review from a team as a code owner October 11, 2021 21:46
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Oct 11, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 11, 2021
@tswast
Copy link
Contributor

tswast commented Oct 11, 2021

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

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
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?

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
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
Contributor Author

Choose a reason for hiding this comment

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

Ah, got it! Thanks!

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
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 tswast October 26, 2021 19:49
@tswast tswast 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-green bot merged commit fe16adc into googleapis:main Nov 1, 2021
@gcf-merge-on-green gcf-merge-on-green bot 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)

🦕
abdelmegahedgoogle pushed a commit to abdelmegahedgoogle/python-bigquery that referenced this pull request Apr 17, 2023
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 API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants