Skip to content

fix(ndb): use the single-argument generator.throw() signature - #18159

Merged
parthea merged 1 commit into
googleapis:mainfrom
skippdot:fix-ndb-deprecated-generator-throw
Aug 19, 2026
Merged

fix(ndb): use the single-argument generator.throw() signature#18159
parthea merged 1 commit into
googleapis:mainfrom
skippdot:fix-ndb-deprecated-generator-throw

Conversation

@skippdot

Copy link
Copy Markdown
Contributor

Fixes #18158

Summary

_TaskletFuture._advance_tasklet throws exceptions into the wrapped generator using the three-argument form of generator.throw(), deprecated in Python 3.12:

if error:
    traceback = error.__traceback__
    yielded = self.generator.throw(type(error), error, traceback)

Every exception that crosses a tasklet boundary emits a DeprecationWarning. This library's own unit suite raises 70 warnings today; with this change it raises 36, so 34 of them came from this single line.

Today that is only noise, but the Python docs say the old signature "may be removed in a future version". noxfile.py already lists 3.15 in ALL_INTERPRETERS, so it is worth landing before that removal makes every tasklet-boundary exception raise TypeError instead of propagating.

Changes

The single-argument form reads the traceback off the exception itself, so the local becomes redundant:

if error:
    yielded = self.generator.throw(error)

Also adds a regression test asserting both halves of the contract: the exception still arrives with its __traceback__ intact, and no DeprecationWarning is emitted. I verified the test fails against the old line and passes against the new one, so it genuinely guards the behaviour rather than just tracking it.

Verification

@skippdot
skippdot requested a review from a team as a code owner August 19, 2026 12:40
@google-cla

google-cla Bot commented Aug 19, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request simplifies exception propagation in tasklets by replacing the legacy three-argument generator.throw() call with the single-argument version generator.throw(error). This avoids DeprecationWarning in newer Python versions while preserving the traceback. A corresponding regression test has been added to verify this behavior and ensure no deprecation warnings are raised. There are no review comments, and no further feedback is required.

The three-argument form deprecated in Python 3.12 emits a DeprecationWarning
for every exception crossing a tasklet boundary, and the docs say it may be
removed in a future version, which would turn each of those into a TypeError.

The single-argument form reads the traceback off the exception itself, so the
local becomes redundant and the delivered exception is unchanged.
@skippdot
skippdot force-pushed the fix-ndb-deprecated-generator-throw branch from 78e0ce2 to 4abc826 Compare August 19, 2026 13:00
@parthea parthea added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Aug 19, 2026
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Aug 19, 2026
@parthea parthea self-assigned this Aug 19, 2026

@parthea parthea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @skippdot!

@parthea
parthea enabled auto-merge (squash) August 19, 2026 15:19
@parthea parthea removed their assignment Aug 19, 2026
@parthea
parthea merged commit dfb0e36 into googleapis:main Aug 19, 2026
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

google-cloud-ndb: DeprecationWarning from the three-arg generator.throw() in tasklets

4 participants