Skip to content

Commit

Permalink
Fix proto and add SA validation
Browse files Browse the repository at this point in the history
  • Loading branch information
cretz committed Jun 9, 2022
1 parent 5585bdc commit 4a10595
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ These steps can be followed to use with a virtual environment and `pip`:

The SDK is now ready for use. To build from source, see "Building" near the end of this documentation.

**NOTE: This README is for the current branch and not necessarily what's released on `PyPI`.**

### Implementing a Workflow

Create the following script at `run_worker.py`:
Expand Down
4 changes: 3 additions & 1 deletion scripts/gen_protos.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def fix_generated_output(base_path: Path):
# MyPy protobuf does not document this experimental class, see
# https://github.com/nipunn1313/mypy-protobuf/issues/212#issuecomment-885300106
import_suffix = ""
if stem == "service_pb2_grpc" and message == "WorkflowService":
if stem == "service_pb2_grpc" and (
message == "WorkflowService" or message == "OperatorService"
):
import_suffix = " # type: ignore"
f.write(f"from .{stem} import {message}{import_suffix}\n")
message_names.append(message)
Expand Down
2 changes: 1 addition & 1 deletion temporalio/api/operatorservice/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
RemoveSearchAttributesRequest,
RemoveSearchAttributesResponse,
)
from .service_pb2_grpc import OperatorService # type: ignore
from .service_pb2_grpc import (
OperatorService,
OperatorServiceServicer,
OperatorServiceStub,
add_OperatorServiceServicer_to_server,
Expand Down
4 changes: 4 additions & 0 deletions temporalio/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ def encode_search_attribute_values(
"Timezone must be present on all search attribute dates"
)
v = v.isoformat()
elif not isinstance(v, (str, int, float, bool)):
raise TypeError(
f"Search attribute value of type {type(v).__name__} not one of str, int, float, bool, or datetime"
)
safe_vals.append(v)
return default().payload_converter.to_payloads([safe_vals])[0]

Expand Down
8 changes: 8 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from datetime import datetime

import pytest

Expand Down Expand Up @@ -99,3 +100,10 @@ def test_binary_proto():
assert payload.data == proto.SerializeToString()
decoded = conv.from_payload(payload)
assert decoded == proto


def test_encode_search_attribute_values():
with pytest.raises(TypeError, match="of type tuple not one of"):
temporalio.converter.encode_search_attribute_values([("bad type",)])
with pytest.raises(ValueError, match="Timezone must be present"):
temporalio.converter.encode_search_attribute_values([datetime.utcnow()])

0 comments on commit 4a10595

Please sign in to comment.