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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: The DB API Binary function accepts bytes data #630

Merged
merged 8 commits into from Apr 27, 2021
Merged

Conversation

jimfulton
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)

Fixes #628 馃

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Apr 26, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Apr 26, 2021
Because we don't want to accidentally create a giant bytes.
if isinstance(data, int):
# This is not the conversion we're looking for, because it
# will simply create a bytes object of the given size.
raise TypeError("cannot convert 'decimal.Decimal' object to binary")
Copy link
Contributor

Choose a reason for hiding this comment

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

isinstance is checking for int, but the error says decimal.Decimal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. 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.

Done

@@ -13,6 +13,7 @@
# limitations under the License.

import datetime
import pytest
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We usually put pytest in the second grouping of imports rather than with the built-ins. We do try to follow PEP-8 advice.

Imports should be grouped in the following order:

  1. Standard library imports.
  2. Related third party imports.
  3. Local application/library specific imports.

You should put a blank line between each group of imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


self.assertEqual(types.Binary(C()), b"Google")

for bad in 42, 42.0, None:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect the tests for "bad inputs" to be in a separate test function.

Ideally both of these (good inputs, bad inputs) would be parameterized in pytest-style tests. I think we can actually mix those in to the same file, so we can do that without refactoring everything, especially since these tests don't require any of the setup from the unit test class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jimfulton jimfulton marked this pull request as ready for review April 27, 2021 19:52
@jimfulton jimfulton requested review from a team and stephaniewang526 and removed request for a team April 27, 2021 19:52
tswast
tswast approved these changes Apr 27, 2021
@tswast tswast merged commit 4396e70 into master Apr 27, 2021
10 checks passed
@tswast tswast deleted the riversnake-fix-628 branch April 27, 2021 20:15
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.

The DB API Binary function should accept bytes.
2 participants