Skip to content

Commit 89b6e66

Browse files
authored
Support both protobuf 3 and 4 (#215)
1 parent e37b500 commit 89b6e66

File tree

58 files changed

+6451
-1234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+6451
-1234
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
- os: ubuntu-latest
1919
python: "3.11"
2020
docsTarget: true
21+
- os: ubuntu-latest
22+
python: "3.7"
2123
protoCheckTarget: true
2224
- os: ubuntu-arm
2325
runsOn: buildjet-4vcpu-ubuntu-2204-arm
@@ -52,13 +54,21 @@ jobs:
5254
- if: ${{ !endsWith(matrix.os, '-arm') }}
5355
run: poe test -s -o log_cli_level=DEBUG --workflow-environment time-skipping
5456

55-
# Confirm protos are already generated properly
56-
- name: Check generated protos
57+
# Confirm protos are already generated properly with older protobuf
58+
# library and run test with that older version. We must downgrade protobuf
59+
# so we can generate 3.x and 4.x compatible API. We have to use older
60+
# Python to run this check because the grpcio-tools version we use
61+
# is <= 3.10.
62+
- name: Check generated protos and test protobuf 3.x
5763
if: ${{ matrix.protoCheckTarget }}
64+
env:
65+
TEMPORAL_TEST_PROTO3: 1
5866
run: |
67+
poetry add "protobuf<4"
5968
poe gen-protos
6069
poe format
61-
[[ -z $(git status --porcelain) ]] || (git diff; echo "Protos changed"; exit 1)
70+
[[ -z $(git status --porcelain temporalio) ]] || (git diff; echo "Protos changed"; exit 1)
71+
poe test -s -o log_cli_level=DEBUG
6272
6373
# Do docs stuff (only on one host)
6474
- name: Build API docs

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ The Python SDK is under development. There are no compatibility guarantees at th
9292
- [Testing](#testing-1)
9393
- [Workflow Replay](#workflow-replay)
9494
- [OpenTelemetry Support](#opentelemetry-support)
95+
- [Protobuf 3.x vs 4.x](#protobuf-3x-vs-4x)
9596
- [Development](#development)
9697
- [Building](#building)
9798
- [Prepare](#prepare)
9899
- [Build](#build)
99100
- [Use](#use)
100101
- [Local SDK development environment](#local-sdk-development-environment)
101102
- [Testing](#testing-2)
103+
- [Proto Generation and Testing](#proto-generation-and-testing)
102104
- [Style](#style)
103105

104106
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -971,6 +973,18 @@ as an interceptor on the `interceptors` argument of `Client.connect`. When set,
971973
calls and for all activity and workflow invocations on the worker, spans will be created and properly serialized through
972974
the server to give one proper trace for a workflow execution.
973975

976+
### Protobuf 3.x vs 4.x
977+
978+
Python currently has two somewhat-incompatible protobuf library versions - the 3.x series and the 4.x series. Python
979+
currently recommends 4.x and that is the primary supported version. Some libraries like
980+
[Pulumi](https://github.com/pulumi/pulumi) require 4.x. Other libraries such as [ONNX](https://github.com/onnx/onnx) and
981+
[Streamlit](https://github.com/streamlit/streamlit), for one reason or another, have/will not leave 3.x.
982+
983+
To support these, Temporal Python SDK allows any protobuf library >= 3.19. However, the C extension in older Python
984+
versions can cause issues with the sandbox due to global state sharing. Temporal strongly recommends using the latest
985+
protobuf 4.x library unless you absolutely cannot at which point some proto libraries may have to be marked as
986+
[Passthrough Modules](#passthrough-modules).
987+
974988
## Development
975989

976990
The Python SDK is built to work with Python 3.7 and newer. It is built using
@@ -1117,6 +1131,16 @@ This runs against [Temporalite](https://github.com/temporalio/temporalite). To r
11171131
server, pass `--workflow-environment time-skipping`. To run against the `default` namespace of an already-running
11181132
server, pass the `host:port` to `--workflow-environment`.
11191133

1134+
#### Proto Generation and Testing
1135+
1136+
To allow for backwards compatibility, protobuf code is generated on the 3.x series of the protobuf library. To generate
1137+
protobuf code, you must be on Python <= 3.10, and then run `poetry add "protobuf<4"`. Then the protobuf files can be
1138+
generated via `poe gen-protos`. Tests can be run for protobuf version 3 by setting the `TEMPORAL_TEST_PROTO3` env var
1139+
to `1` prior to running tests.
1140+
1141+
Do not commit `poetry.lock` or `pyproject.toml` changes. To go back from this downgrade, restore `pyproject.toml` and
1142+
run `poetry update protobuf grpcio-tools`.
1143+
11201144
### Style
11211145

11221146
* Mostly [Google Style Guide](https://google.github.io/styleguide/pyguide.html). Notable exceptions:

poetry.lock

Lines changed: 113 additions & 113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ script = "build.py"
2828
grpcio = { version = "^1.48.0", optional = true }
2929
opentelemetry-api = { version = "^1.11.1", optional = true }
3030
opentelemetry-sdk = { version = "^1.11.1", optional = true }
31-
protobuf = "~4.21"
31+
protobuf = ">=3.19"
3232
python = "^3.7"
3333
python-dateutil = { version = "^2.8.2", python = "<3.11" }
3434
types-protobuf = "~3.20"

0 commit comments

Comments
 (0)