Skip to content

Commit

Permalink
Don't leak StopIteration from a generator (PEP-479) (#90)
Browse files Browse the repository at this point in the history
* Revert "Fix generator raised StopIteration error (#89)"

This reverts commit 1609123.

* Don't leak StopIteration from a generator (see PEP-479).

* Bump version to 1.1.5.
  • Loading branch information
jnturton authored Jun 10, 2024
1 parent 9d11403 commit 27c8aa8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_drill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
29 changes: 15 additions & 14 deletions sqlalchemy_drill/drilldbapi/_drilldbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}'
Expand Down Expand Up @@ -516,20 +511,26 @@ 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:
if event in ('start_map', 'start_array'):
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:
Expand Down Expand Up @@ -610,4 +611,4 @@ def TimestampFromTicks(ticks):


class Binary(bytes):
"""Construct an object capable of holding a binary (long) string value."""
"""Construct an object capable of holding a binary (long) string value."""

0 comments on commit 27c8aa8

Please sign in to comment.