From 27c8aa8248ef61307df7c8159b1bb6e095b814d2 Mon Sep 17 00:00:00 2001 From: James Turton <9107319+jnturton@users.noreply.github.com> Date: Mon, 10 Jun 2024 05:03:35 +0200 Subject: [PATCH] Don't leak StopIteration from a generator (PEP-479) (#90) * Revert "Fix generator raised StopIteration error (#89)" This reverts commit 160912306c15d3069ec91af3dd203de9cd396b00. * Don't leak StopIteration from a generator (see PEP-479). * Bump version to 1.1.5. --- CHANGELOG.md | 12 +++++++++ setup.py | 4 +-- sqlalchemy_drill/__init__.py | 2 +- sqlalchemy_drill/drilldbapi/_drilldbapi.py | 29 +++++++++++----------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e7f704..efbb107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ ## [Unreleased] +## [1.1.5] - 2024-06-04 + +### Fixed + +- Fix a leaked StopIteration from a generator. + +## [1.1.4] - 2023-10-23 + +### Fixed + +- Add 'properties' as a reserved word. + ## [1.1.3] - 2022-05-03 ### Changed diff --git a/setup.py b/setup.py index 10dc0e8..d0094f0 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ long_description = f.read() setup(name='sqlalchemy_drill', - version='1.1.4', + version='1.1.5', description="Apache Drill for SQLAlchemy", long_description=long_description, long_description_content_type="text/markdown", @@ -64,7 +64,7 @@ license='MIT', url='https://github.com/JohnOmernik/sqlalchemy-drill', download_url='https://github.com/JohnOmernik/sqlalchemy-drill/archive/' - '1.1.4.tar.gz', + '1.1.5.tar.gz', packages=find_packages(), include_package_data=True, tests_require=['nose >= 0.11'], diff --git a/sqlalchemy_drill/__init__.py b/sqlalchemy_drill/__init__.py index 632b4bb..42e9fc1 100755 --- a/sqlalchemy_drill/__init__.py +++ b/sqlalchemy_drill/__init__.py @@ -19,7 +19,7 @@ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -__version__ = '1.1.3' +__version__ = '1.1.5' from sqlalchemy.dialects import registry registry.register("drill", "sqlalchemy_drill.sadrill", "DrillDialect_sadrill") diff --git a/sqlalchemy_drill/drilldbapi/_drilldbapi.py b/sqlalchemy_drill/drilldbapi/_drilldbapi.py index e611393..ba12fd2 100755 --- a/sqlalchemy_drill/drilldbapi/_drilldbapi.py +++ b/sqlalchemy_drill/drilldbapi/_drilldbapi.py @@ -110,16 +110,11 @@ def _report_query_state(self): logger.warning(exception) logger.warning(error_message) logger.warning(stack_trace) - logger.info(query_state) - logger.error(error_message) - ''' raise DatabaseError( f'Final Drill query state is {query_state}. {error_message}', None ) - ''' - return def _outer_parsing_loop(self) -> bool: '''Internal method to process the outermost query result JSON structure. @@ -282,7 +277,7 @@ def fetchmany(self, size: int = None): if self.rownumber % api_globals._PROGRESS_LOG_N == 0: logger.info(f'streamed {self.rownumber} rows.') - except: + except StopIteration: self.rowcount = self.rownumber logger.info( f'reached the end of the row data after {self.rownumber}' @@ -516,7 +511,10 @@ def _items_once(event_stream, prefix): ''' current = None while current != prefix: - current, event, value = next(event_stream) + try: + current, event, value = next(event_stream) + except StopIteration: + return # see PEP-479 logger.debug(f'found and will now parse an occurrence of {prefix}') while current == prefix: @@ -524,12 +522,15 @@ def _items_once(event_stream, prefix): object_depth = 1 builder = ObjectBuilder() while object_depth: - builder.event(event, value) - current, event, value = next(event_stream) - if event in ('start_map', 'start_array'): - object_depth += 1 - elif event in ('end_map', 'end_array'): - object_depth -= 1 + try: + builder.event(event, value) + current, event, value = next(event_stream) + if event in ('start_map', 'start_array'): + object_depth += 1 + elif event in ('end_map', 'end_array'): + object_depth -= 1 + except StopIteration: + return # see PEP-479 del builder.containers[:] yield builder.value else: @@ -610,4 +611,4 @@ def TimestampFromTicks(ticks): class Binary(bytes): - """Construct an object capable of holding a binary (long) string value.""" \ No newline at end of file + """Construct an object capable of holding a binary (long) string value."""