Skip to content

raise StopIteration inside generator in query.py causes RuntimeError (PEP 479) #1786

@jacalata

Description

@jacalata

In tableauserverclient/server/query.py, QuerySet.__iter__ catches a 400006 "invalid page number" error (which signals the end of pagination on some endpoints) and raises StopIteration to break out of the loop:

except ServerResponseError as e:
    if e.code == "400006":
        raise StopIteration  # PEP 479: converted to RuntimeError inside generator

Since Python 3.7 (PEP 479), StopIteration raised inside a generator frame is automatically converted to RuntimeError. Because __iter__ is a generator (it uses yield from), this path raises RuntimeError instead of ending iteration cleanly.

We confirmed this locally — iterating a QuerySet against an endpoint that returns 400006 on page 2 raises:

RuntimeError: generator raised StopIteration

The fix is to return from the generator directly rather than raising StopIteration:

except ServerResponseError as e:
    if e.code == "400006":
        return  # cleanly ends the generator

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions