Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nulls send in in-band sync response #206

Merged
merged 4 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 11 additions & 48 deletions pkg/inngest/inngest/_internal/comm_lib/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,53 +65,6 @@ def __init__(

self._signing_key_fallback = client.signing_key_fallback

def _build_register_request(
self,
*,
app_url: str,
server_kind: typing.Optional[server_lib.ServerKind],
sync_id: typing.Optional[str],
) -> types.MaybeError[httpx.Request]:
registration_url = urllib.parse.urljoin(
self._api_origin,
"/fn/register",
)

fn_configs = self.get_function_configs(app_url)
if isinstance(fn_configs, Exception):
return fn_configs

body = server_lib.SynchronizeRequest(
app_name=self._client.app_id,
deploy_type=server_lib.DeployType.PING,
framework=self._framework,
functions=fn_configs,
sdk=f"{const.LANGUAGE}:v{const.VERSION}",
url=app_url,
v="0.1",
).to_dict()
if isinstance(body, Exception):
return body

headers = net.create_headers(
env=self._client.env,
framework=self._framework,
server_kind=server_kind,
)

params = {}
if sync_id is not None:
params[server_lib.QueryParamKey.SYNC_ID.value] = sync_id

return self._client._http_client_sync.build_request(
"POST",
registration_url,
headers=headers,
json=transforms.deep_strip_none(body),
params=params,
timeout=30,
)

@wrap_handler()
async def post(
self,
Expand Down Expand Up @@ -539,6 +492,11 @@ def in_band(
if isinstance(res_body, Exception):
return res_body

# Remove any None values from the response body. If we don't Go
# marshalling may break in the Inngest server. Specifically, we saw this
# with the concurrency scope.
res_body = transforms.deep_strip_none(res_body)

self._logger.debug("Responding to in-band sync")

return CommResponse(
Expand Down Expand Up @@ -615,11 +573,16 @@ def _create_out_of_band_request(
params.sync_id
)

# Remove any None values from the response body. If we don't Go
# marshalling may break in the Inngest server. Specifically, we saw this
# with the concurrency scope.
body = transforms.deep_strip_none(body)

return handler._client._http_client_sync.build_request(
"POST",
registration_url,
headers=headers,
json=transforms.deep_strip_none(body),
json=body,
params=outgoing_params,
timeout=30,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/inngest/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "inngest"
version = "0.4.19"
version = "0.4.20"
authors = [{ name = "Inngest Inc.", email = "hello@inngest.com" }]
description = "Python SDK for Inngest"
readme = "README.md"
Expand Down
18 changes: 0 additions & 18 deletions pytest.ini

This file was deleted.

6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest

# Make `assert` calls display a useful diff when they fail. Without this,
# `assert` failures just show "AssertionError" with no helpful diff.
pytest.register_assert_rewrite("test_inngest")
pytest.register_assert_rewrite("test_inngest_encryption")
2 changes: 0 additions & 2 deletions tests/test_inngest/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
from inngest.experimental import dev_server

pytest.register_assert_rewrite("tests")


def pytest_configure(config: pytest.Config) -> None:
dev_server.server.start()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_inngest/test_function/cases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
asyncio_first_completed,
asyncio_gather,
asyncio_immediate_execution,
base,
batch_that_needs_api,
cancel,
change_step_error,
Expand Down Expand Up @@ -47,6 +46,7 @@
wait_for_event_timeout_if_exp_not_match,
wait_for_event_timeout_name_not_match,
)
from .base import Case

_modules = (
asyncio_gather,
Expand Down Expand Up @@ -98,7 +98,7 @@
def create_async_cases(
client: inngest.Inngest,
framework: server_lib.Framework,
) -> list[base.Case]:
) -> list[Case]:
return [
module.create(client, framework, is_sync=False) for module in _modules
]
Expand All @@ -107,7 +107,7 @@ def create_async_cases(
def create_sync_cases(
client: inngest.Inngest,
framework: server_lib.Framework,
) -> list[base.Case]:
) -> list[Case]:
cases = []
for module in _modules:
case = module.create(client, framework, is_sync=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _assert_results(
actual: list[inngest.TransformOutputResult],
expected: list[inngest.TransformOutputResult],
) -> None:
assert len(actual) == len(expected)

for i, (a, e) in enumerate(zip(actual, expected)):
assert a.__dict__ == e.__dict__, f"index={i}"

assert len(actual) == len(expected)
15 changes: 1 addition & 14 deletions tests/test_inngest/test_registration/cases/cloud_branch_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,8 @@ def fn(
"framework": framework.value,
"functions": [
{
"batchEvents": None,
"cancel": None,
"concurrency": None,
"debounce": None,
"id": fn.id,
"idempotency": None,
"name": "foo",
"priority": None,
"rateLimit": None,
"steps": {
"step": {
"id": "step",
Expand All @@ -95,8 +88,7 @@ def fn(
},
}
},
"throttle": None,
"triggers": [{"event": "app/foo", "expression": None}],
"triggers": [{"event": "app/foo"}],
}
],
"inspection": {
Expand All @@ -107,7 +99,6 @@ def fn(
"capabilities": {"in_band_sync": "v1", "trust_probe": "v1"},
"env": "my-env",
"event_api_origin": "https://inn.gs/",
"event_key_hash": None,
"framework": framework.value,
"function_count": 1,
"has_event_key": False,
Expand All @@ -116,12 +107,8 @@ def fn(
"mode": "cloud",
"sdk_language": "py",
"sdk_version": const.VERSION,
"serve_origin": None,
"serve_path": None,
"signing_key_fallback_hash": None,
"signing_key_hash": "709e80c88487a2411e1ee4dfb9f22a861492d20c4765150c0c794abd70f8147c",
},
"platform": None,
"sdk_author": "inngest",
"sdk_language": "py",
"sdk_version": const.VERSION,
Expand Down
2 changes: 0 additions & 2 deletions tests/test_inngest_encryption/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
from inngest.experimental import dev_server

pytest.register_assert_rewrite("tests")


def pytest_configure(config: pytest.Config) -> None:
dev_server.server.start()
Expand Down