GeezerVison is showing github.com — fix: PubSub incompatibility with api-core 1.17.0+ (#103) · googleapis/python-pubsub@c02060f
This repository was archived by the owner on Oct 13, 2026. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings google/cloud/pubsub_v1/gapic tests/unit/pubsub_v1/subscriber
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: google/cloud/pubsub_v1/gapic/subscriber_client.py +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1175,6 +1175,11 @@ def streaming_pull( | 1175 | 1175 | client_info=self._client_info, | 1176 | 1176 | ) | 1177 | 1177 |
| | 1178 | + # Wrappers in api-core should not automatically pre-fetch the first | | 1179 | + # stream result, as this breaks the stream when re-opening it. | | 1180 | + # https://github.com/googleapis/python-pubsub/issues/93#issuecomment-630762257 | | 1181 | + self.transport.streaming_pull._prefetch_first_result_ = False | | 1182 | + | 1178 | 1183 | return self._inner_api_calls["streaming_pull"]( | 1179 | 1184 | requests, retry=retry, timeout=timeout, metadata=metadata | 1180 | 1185 | ) | |
Collapse file Copy file name to clipboardExpand all lines: setup.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 29 | 29 | # 'Development Status :: 5 - Production/Stable' | 30 | 30 | release_status = "Development Status :: 5 - Production/Stable" | 31 | 31 | dependencies = [ | 32 | | - # google-api-core[grpc] 1.17.0 causes problems, thus restricting its | 33 | | - # version until the issue gets fixed. | | 32 | + # google-api-core[grpc] 1.17.0 up to 1.19.1 causes problems with stream | | 33 | + # recovery, thus those versions should not be used. | 34 | 34 | # https://github.com/googleapis/python-pubsub/issues/74 | 35 | | - "google-api-core[grpc] >= 1.14.0, < 1.17.0", | | 35 | + "google-api-core[grpc] >= 1.14.0, != 1.17.*, != 1.18.*, != 1.19.*", | 36 | 36 | "grpc-google-iam-v1 >= 0.12.3, < 0.13dev", | 37 | 37 | 'enum34; python_version < "3.4"', | 38 | 38 | ] | |
Collapse file Copy file name to clipboardExpand all lines: synth.py +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -185,6 +185,20 @@ def _merge_dict(d1, d2): | 185 | 185 | "from google.iam.v1 import iam_policy_pb2_grpc as iam_policy_pb2", | 186 | 186 | ) | 187 | 187 |
| | 188 | +# Monkey patch the streaming_pull() GAPIC method to disable pre-fetching stream | | 189 | +# results. | | 190 | +s.replace( | | 191 | + "google/cloud/pubsub_v1/gapic/subscriber_client.py", | | 192 | + r"return self\._inner_api_calls\['streaming_pull'\]\(.*", | | 193 | + """ | | 194 | + # Wrappers in api-core should not automatically pre-fetch the first | | 195 | + # stream result, as this breaks the stream when re-opening it. | | 196 | + # https://github.com/googleapis/python-pubsub/issues/93#issuecomment-630762257 | | 197 | + self.transport.streaming_pull._prefetch_first_result_ = False | | 198 | +
| | 199 | + \g<0>""" | | 200 | +) | | 201 | + | 188 | 202 | # Add missing blank line before Attributes: in generated docstrings | 189 | 203 | # https://github.com/googleapis/protoc-docs-plugin/pull/31 | 190 | 204 | s.replace( | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/pubsub_v1/subscriber/test_subscriber_client.py +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -154,3 +154,15 @@ def test_closes_channel_as_context_manager(): | 154 | 154 | pass | 155 | 155 |
| 156 | 156 | mock_transport.channel.close.assert_called() | | 157 | + | | 158 | + | | 159 | +def test_streaming_pull_gapic_monkeypatch(): | | 160 | + transport = mock.NonCallableMock(spec=["streaming_pull"]) | | 161 | + transport.streaming_pull = mock.Mock(spec=[]) | | 162 | + client = subscriber.Client(transport=transport) | | 163 | + | | 164 | + client.streaming_pull(requests=iter([])) | | 165 | + | | 166 | + assert client.api.transport is transport | | 167 | + assert hasattr(transport.streaming_pull, "_prefetch_first_result_") | | 168 | + assert not transport.streaming_pull._prefetch_first_result_ |
|