Skip to content

Commit fe7bfd0

Browse files
fixedbydevparthea
andauthored
fix: remove stray debug print in RangeQueryParameter constructor (#17973)
`RangeQueryParameter.__init__` in `google-cloud-bigquery` has a leftover debug `print()`: ```python self.range_element_type = self._parse_range_element_type(range_element_type) print(self.range_element_type.type_._type) # <- this self.start = start ``` It fires on every construction, so anyone building a RANGE query parameter gets the element type dumped to stdout. Easy to reproduce: ```python >>> from google.cloud.bigquery.query import RangeQueryParameter >>> RangeQueryParameter(range_element_type="DATE", start="2016-08-11") DATE ``` This removes the line and adds a small regression test that asserts nothing is printed during construction. Verified the test fails on the current code (`Expected 'print' to not have been called. Called 1 times. Calls: [call('DATE')]`) and passes after the removal. All existing RangeQueryParameter tests still pass, black is clean. Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 6ff5815 commit fe7bfd0

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

packages/google-cloud-bigquery/google/cloud/bigquery/query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,6 @@ def __init__(
10201020
):
10211021
self.name = name
10221022
self.range_element_type = self._parse_range_element_type(range_element_type)
1023-
print(self.range_element_type.type_._type)
10241023
self.start = start
10251024
self.end = end
10261025

packages/google-cloud-bigquery/tests/unit/test_query.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,13 @@ def test_ctor(self):
778778
self.assertEqual(param.start, "2016-08-11")
779779
self.assertIs(param.end, None)
780780

781+
def test_ctor_does_not_print_to_stdout(self):
782+
# Regression test for a stray debug print() in __init__ that wrote the
783+
# range element type to stdout on every construction.
784+
with mock.patch("builtins.print") as mock_print:
785+
self._make_one(range_element_type="DATE", start="2016-08-11")
786+
mock_print.assert_not_called()
787+
781788
def test_ctor_w_datetime_query_parameter_type_str(self):
782789
from google.cloud.bigquery.query import RangeQueryParameterType
783790

0 commit comments

Comments
 (0)