GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: ensure exception is available when BackgroundConsumer open stream fails by parthea · Pull Request #357 · googleapis/python-api-core

This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Conversation

@parthea

@parthea parthea commented Mar 14, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #268🦕

This PR updates the bidi.py code to reflect what is stated in the comments.

The comment for add_done_callback states This occurs when the RPC errors or is successfully terminated. however the done callback was not being called when an error occurs.

python-api-core/google/api_core/bidi.py

Lines 255 to 264 in 2477ab9

def add_done_callback(self, callback):
"""Adds a callback that will be called when the RPC terminates.
This occurs when the RPC errors or is successfully terminated.
Args:
callback (Callable[[grpc.Future], None]): The callback to execute.
It will be provided with the same gRPC future as the underlying
stream which will also be a :class:`grpc.Call`.
"""

python-api-core/google/api_core/bidi.py

Lines 267 to 269 in 2477ab9

def _on_call_done(self, future):
for callback in self._callbacks:
callback(future)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@parthea
parthea requested review from a team March 14, 2022 20:37
@parthea
parthea force-pushed the fix-background-consumer-start-eats-exception branch from 7f05e51 to 767b215 Compare March 14, 2022 20:38
@parthea
fix: ensure exception is available when BackgroundConsumer open strea…
1a64fff
…m fails
@parthea
parthea force-pushed the fix-background-consumer-start-eats-exception branch from 767b215 to 1a64fff Compare March 14, 2022 20:40
@parthea parthea mentioned this pull request Mar 14, 2022
fix: handle AttributeError in bigquery_storage writer googleapis/python-bigquery-storage#414
Merged
@parthea
chore: fix coverage
97c2363
@parthea
parthea force-pushed the fix-background-consumer-start-eats-exception branch from dddb4d3 to 97c2363 Compare March 15, 2022 13:18
tswast
tswast previously requested changes Mar 15, 2022
View reviewed changes

@tswast tswast left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This looks great! Let's block this until we figure out google-cloud-bigquery-storage though. googleapis/python-bigquery-storage#414

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

parthea reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
atulep
atulep reviewed Apr 26, 2022
View reviewed changes
Comment thread google/api_core/bidi.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

atulep
atulep reviewed Apr 26, 2022
View reviewed changes
Comment thread google/api_core/bidi.py Outdated
try:
call = self._start_rpc(iter(request_generator), metadata=self._rpc_metadata)
except exceptions.GoogleAPICallError as exc:
self._on_call_done(exc)

@atulep atulep Apr 26, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

on_call_done expects a future (based on the name of its argument). How does it work with an exception here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@parthea parthea Jun 14, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The exception will be raised in the call back add_done_callback and must be handled by the user. This is based on the comment here:

python-api-core/google/api_core/bidi.py

Lines 608 to 610 in 8f73d2e

Note that error handling *must* be done by using the provided
``bidi_rpc``'s ``add_done_callback``. This helper will automatically exit
whenever the RPC itself exits and will not provide any error details.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vchudnov-g vchudnov-g Sep 28, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

add_done_callback specifies callback (Callable[[grpc.Future], None]), but it's not clear to me that GoogleAPICallError is a grpc.Future (see this)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@parthea parthea Oct 13, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The change that I proposed is exactly the same behaviour as the _on_call_done method of ResumableBidiRpc

python-api-core/google/api_core/bidi.py

Lines 441 to 443 in 6251eab

# Unlike the base class, we only execute the callbacks on a terminal
# error, not for errors that we can recover from. Note that grpc's
# "future" here is also a grpc.RpcError.

From grpc/grpc#10885 (comment), grpc.RpcError is also grpc.Call.

I added this note in c7f63bd

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@parthea parthea Oct 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I reverted c7f63bd because GoogleAPICallError is not grpc.Call or grpc.RpcError. The original grpc.RpcError is available on the response property of GoogleAPICallError

python-api-core/google/api_core/grpc_helpers.py

Lines 174 to 182 in 6251eab

def wrap_errors(callable_):
"""Wrap a gRPC callable and map :class:`grpc.RpcErrors` to friendly error
classes.
Errors raised by the gRPC callable are mapped to the appropriate
:class:`google.api_core.exceptions.GoogleAPICallError` subclasses.
The original `grpc.RpcError` (which is usually also a `grpc.Call`) is
available from the ``response`` property on the mapped exception. This
is useful for extracting metadata from the original error.

The behaviour proposed in this PR is the same as ResumableBidiRpc and we typically raise GoogleAPICallError instead of grpc.RpcError

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@parthea parthea Oct 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I changed the code in 753a591 to raise grpc.RpcError instead of GoogleAPICallError since grpc.RpcError is also grpc.Call and it is a better fit

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@parthea
Merge branch 'main' into fix-background-consumer-start-eats-exception
2b24714
@product-auto-label product-auto-label Bot added the size: s Pull request size is small. label Jun 14, 2022
@parthea
parthea requested review from atulep and tswast June 24, 2022 15:31
@parthea
parthea dismissed tswast’s stale review June 30, 2022 02:22

Dismiss stale review

@parthea parthea assigned loferris Jun 30, 2022
@parthea
parthea requested a review from loferris June 30, 2022 02:22
@parthea

parthea commented Jun 30, 2022

Copy link
Copy Markdown
Contributor Author

@loferris, please could you review/approve?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@parthea
parthea requested a review from steffnay June 30, 2022 02:24
@parthea parthea assigned steffnay Jun 30, 2022
@parthea
Merge branch 'main' into fix-background-consumer-start-eats-exception
947b657
@tswast
tswast requested a review from rosiezou January 24, 2023 22:02
@tswast

tswast commented Jan 24, 2023

Copy link
Copy Markdown
Contributor

@rosiezou You might be interested in this PR. I forget the full context, but I know it's something I wanted for better debugging of the Python BQ Storage Write API.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rosiezou and others added 2 commits February 3, 2023 11:50
@rosiezou
Merge branch 'main' into fix-background-consumer-start-eats-exception
ad1f29f
@parthea
Merge branch 'main' into fix-background-consumer-start-eats-exception
7ec7832
@parthea parthea assigned vchudnov-g and unassigned steffnay and loferris Sep 1, 2023
@brianhlee

brianhlee commented Sep 19, 2023

Copy link
Copy Markdown

@parthea any idea when this will be merged?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@parthea

parthea commented Sep 19, 2023

Copy link
Copy Markdown
Contributor Author

@vchudnov-g Please could you take a look?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vchudnov-g
vchudnov-g reviewed Sep 28, 2023
View reviewed changes
Comment thread google/api_core/bidi.py
self._request_queue, initial_request=self._initial_request
)
call = self._start_rpc(iter(request_generator), metadata=self._rpc_metadata)
try:

@vchudnov-g vchudnov-g Sep 28, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

In examining this file, it seems to me that _RequestQueueGenerator._is_active (lines 91 et seq) should be defd as return self.call is not None and self.call.is_active(). The way it's currently written it will return True when self.call == None

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@parthea parthea Oct 13, 2023

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed in e120a0c

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/api_core/bidi.py Outdated
try:
call = self._start_rpc(iter(request_generator), metadata=self._rpc_metadata)
except exceptions.GoogleAPICallError as exc:
self._on_call_done(exc)

@vchudnov-g vchudnov-g Sep 28, 2023

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

add_done_callback specifies callback (Callable[[grpc.Future], None]), but it's not clear to me that GoogleAPICallError is a grpc.Future (see this)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@parthea parthea assigned parthea and unassigned vchudnov-g Sep 29, 2023
parthea and others added 6 commits October 13, 2023 16:59
@parthea
Address review comments
c7f63bd
@parthea
revert
3304ef1
@parthea
address review feedback
e120a0c
@parthea
raise grpc.RpcError instead of GoogleAPICallError
753a591
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
3c1daa9
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@parthea
Merge branch 'main' into fix-background-consumer-start-eats-exception
9423063
@parthea parthea assigned vchudnov-g and unassigned parthea Oct 13, 2023
@parthea

parthea commented Oct 13, 2023

Copy link
Copy Markdown
Contributor Author

@vchudnov-g Please could you take another look?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast
tswast removed request for atulep, rosiezou and tswast October 13, 2023 21:05
vchudnov-g
vchudnov-g approved these changes Oct 17, 2023
View reviewed changes
@parthea
parthea merged commit 405272c into main Oct 17, 2023
@parthea
parthea deleted the fix-background-consumer-start-eats-exception branch October 17, 2023 19:54
@release-please release-please Bot mentioned this pull request Oct 17, 2023
chore(main): release 2.13.0 #537
Merged
parthea added a commit that referenced this pull request Nov 30, 2023
@parthea
chore: partial revert of PR #357
536c6d2
This reverts commit e120a0c.
parthea added a commit that referenced this pull request Dec 1, 2023
@parthea
fix: fix regression in bidi causing `Thread-ConsumeBidirectionalStr…
40c8ae0
…eam caught unexpected exception and will exit` (#562)

* chore: partial revert of PR #357

This reverts commit e120a0c.

* add comment
This was referenced May 30, 2025
chore(main): release 2.0.0 #822
Closed
chore(main): release 2.0.0 #823
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@loferris loferris Awaiting requested review from loferris
@steffnay steffnay Awaiting requested review from steffnay
3 more reviewers
@atulep atulep atulep left review comments
@vchudnov-g vchudnov-g vchudnov-g approved these changes
@tswast tswast tswast left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@vchudnov-g vchudnov-g

Labels

size: s Pull request size is small.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

bidi.BackgroundConsumer.start() eats exception when _bidi_rpc.open() fails

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@parthea @tswast @brianhlee @vchudnov-g @atulep @steffnay @loferris @rosiezou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.