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: Add table_constraints field to Table model #1755

Merged
merged 31 commits into from Jan 11, 2024

Conversation

dimkonko
Copy link
Contributor

@dimkonko dimkonko commented Dec 14, 2023

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)

Fixes #1754 🦕

Copy link

google-cla bot commented Dec 14, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigquery Issues related to the googleapis/python-bigquery API. labels Dec 14, 2023
@chalmerlowe
Copy link
Contributor

@dimkonko
I am reviewing this PR. Thank you for the hard work you have put in. I appreciate it. I would like to work with you to get this merged. I have reviewed the PR and will be making a few comments on some of the code shortly.

Please see the note above about the CLA. We will need that taken care of to proceed. #1755 (comment)

@chalmerlowe chalmerlowe added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Dec 15, 2023
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Dec 15, 2023
Copy link
Contributor

@chalmerlowe chalmerlowe left a comment

Choose a reason for hiding this comment

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

@dimkonko

Thanks for all this hard work. I appreciate the time and effort.
I would like to request several changes that I hope you can help with. If you need assistance or want to talk anything through, please let us know.


def __eq__(self, other):
if not isinstance(other, PrimaryKey):
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

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

We have several areas of code that coverage.py does not believe are being tested. Those lines of code are:

  • 2968
  • 2985-2987
  • 3019

For line 2968, it does not appear that we have a test that specifically exercises the raise statement by trying to compare an input value that is not a PrimaryKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I missed the coverage part 😅 Thank you for pointing that out. I've added missing coverage in commit 29d1238


def __eq__(self, other):
if not isinstance(other, PrimaryKey):
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding from the Python documentation is that:

TypeError: Is raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch.

This exception may be raised by user code to indicate that an attempted operation on an object is not supported, and is not meant to be. If an object is meant to support a given operation but has not yet provided an implementation, NotImplementedError is the proper exception to raise.

Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError.

Suggested change
raise NotImplementedError
raise TypeError("The value provided is not a BigQuery PrimaryKey.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chalmerlowe oh, right. Thank you. I missed that. It should be return but not raise.
I think we should not raise anything here to not cause errors and to be consistent with the existing code.

Comment on lines 2985 to 2990
if not isinstance(other, ColumnReference):
raise NotImplementedError
return (
self.referenced_column == other.referencing_column
and self.referenced_column == other.referenced_column
)
Copy link
Contributor

Choose a reason for hiding this comment

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

For this portion of the mod (2985-2987), coverage.py indicates that we are not exercising this code fully.

We do have tests that reference ColumnReferences, but not necessarily in a way that fully exercises each line of this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I've added column_references to the __eq__ in commit da663b2

self.column_references = column_references

def __eq__(self, other):
if not isinstance(other, ForeignKey):
Copy link
Contributor

Choose a reason for hiding this comment

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

This (3019) is also identified by coverage.py as being untested


def __eq__(self, other):
if not isinstance(other, ForeignKey):
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

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

Change all NotImplementedErrors as noted in the previous comment to look similar to this:

TypeError("<add a suitable message for the user to figure out the problem.")

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Dec 16, 2023
@dimkonko dimkonko changed the title Add table_constraints field to Table model feat: Add table_constraints field to Table model Dec 16, 2023
@kiraksi kiraksi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 19, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 19, 2023
@chalmerlowe chalmerlowe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 8, 2024
@chalmerlowe chalmerlowe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 8, 2024
tests/unit/test_table.py Outdated Show resolved Hide resolved
tests/unit/test_table.py Outdated Show resolved Hide resolved
tests/unit/test_table.py Outdated Show resolved Hide resolved
@chalmerlowe chalmerlowe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 8, 2024
@chalmerlowe chalmerlowe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 8, 2024
@chalmerlowe chalmerlowe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 9, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 9, 2024
Copy link
Contributor

@chalmerlowe chalmerlowe left a comment

Choose a reason for hiding this comment

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

LGTM.
@dimkonko

Thanks for all your hard work pulling this together and thanks for your patience as I worked through the review process. I am grateful for your time and effort.

@chalmerlowe chalmerlowe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 11, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 11, 2024
@chalmerlowe chalmerlowe merged commit a167f9a into googleapis:main Jan 11, 2024
19 checks passed
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. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add table_constraints field to Table model
4 participants