From 1f652eaf0c23a924a834e8cfb878a61108e35da0 Mon Sep 17 00:00:00 2001 From: Aaron Harper Date: Tue, 4 Mar 2025 14:55:27 -0500 Subject: [PATCH 1/4] Fix nulls send in in-band sync response --- .../inngest/_internal/comm_lib/handler.py | 59 ++++--------------- pkg/inngest/pyproject.toml | 2 +- pytest.ini | 18 ------ tests/conftest.py | 6 ++ tests/test_inngest/conftest.py | 2 - .../cases/cloud_branch_env.py | 15 +---- tests/test_inngest_encryption/conftest.py | 2 - 7 files changed, 19 insertions(+), 85 deletions(-) delete mode 100644 pytest.ini create mode 100644 tests/conftest.py diff --git a/pkg/inngest/inngest/_internal/comm_lib/handler.py b/pkg/inngest/inngest/_internal/comm_lib/handler.py index bf28ff30..7b374691 100644 --- a/pkg/inngest/inngest/_internal/comm_lib/handler.py +++ b/pkg/inngest/inngest/_internal/comm_lib/handler.py @@ -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, @@ -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( @@ -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, ) diff --git a/pkg/inngest/pyproject.toml b/pkg/inngest/pyproject.toml index 685ad811..1ea9b44c 100644 --- a/pkg/inngest/pyproject.toml +++ b/pkg/inngest/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "inngest" -version = "0.4.19" +version = "0.4.20a0" authors = [{ name = "Inngest Inc.", email = "hello@inngest.com" }] description = "Python SDK for Inngest" readme = "README.md" diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 97a3a081..00000000 --- a/pytest.ini +++ /dev/null @@ -1,18 +0,0 @@ -['MESSAGES CONTROL'] -disable = - broad-exception-caught, - broad-exception-raised, - duplicate-code, - fixme, - invalid-envvar-value, - line-too-long, - missing-docstring, - too-few-public-methods, - too-many-arguments, - too-many-instance-attributes, - too-many-return-statements, - unused-argument, - - -[ini_options] -filterwarnings = ignore::pytest.PytestAssertRewriteWarning diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..09b9ef28 --- /dev/null +++ b/tests/conftest.py @@ -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") diff --git a/tests/test_inngest/conftest.py b/tests/test_inngest/conftest.py index b3179f67..bd340d12 100644 --- a/tests/test_inngest/conftest.py +++ b/tests/test_inngest/conftest.py @@ -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() diff --git a/tests/test_inngest/test_registration/cases/cloud_branch_env.py b/tests/test_inngest/test_registration/cases/cloud_branch_env.py index ce641692..6ede7080 100644 --- a/tests/test_inngest/test_registration/cases/cloud_branch_env.py +++ b/tests/test_inngest/test_registration/cases/cloud_branch_env.py @@ -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", @@ -95,8 +88,7 @@ def fn( }, } }, - "throttle": None, - "triggers": [{"event": "app/foo", "expression": None}], + "triggers": [{"event": "app/foo"}], } ], "inspection": { @@ -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, @@ -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, diff --git a/tests/test_inngest_encryption/conftest.py b/tests/test_inngest_encryption/conftest.py index b3179f67..bd340d12 100644 --- a/tests/test_inngest_encryption/conftest.py +++ b/tests/test_inngest_encryption/conftest.py @@ -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() From f1631ae25f4cd70fb60abf7350fb253acee03421 Mon Sep 17 00:00:00 2001 From: Aaron Harper Date: Tue, 4 Mar 2025 15:01:19 -0500 Subject: [PATCH 2/4] Move assert in test to help with flaky test debugging --- .../test_function/cases/middleware_parallel_steps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_inngest/test_function/cases/middleware_parallel_steps.py b/tests/test_inngest/test_function/cases/middleware_parallel_steps.py index 7b7259e9..8c70ae55 100644 --- a/tests/test_inngest/test_function/cases/middleware_parallel_steps.py +++ b/tests/test_inngest/test_function/cases/middleware_parallel_steps.py @@ -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) From 9a8ff7e840acd7048c5619a8821ffd0dbc098db8 Mon Sep 17 00:00:00 2001 From: Aaron Harper Date: Tue, 4 Mar 2025 15:33:50 -0500 Subject: [PATCH 3/4] Fix mypy errors --- tests/test_inngest/test_function/cases/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_inngest/test_function/cases/__init__.py b/tests/test_inngest/test_function/cases/__init__.py index 745daf57..0f588e9e 100644 --- a/tests/test_inngest/test_function/cases/__init__.py +++ b/tests/test_inngest/test_function/cases/__init__.py @@ -5,7 +5,6 @@ asyncio_first_completed, asyncio_gather, asyncio_immediate_execution, - base, batch_that_needs_api, cancel, change_step_error, @@ -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, @@ -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 ] @@ -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) From 99d59994994414cf0ca24e82520499c36f14fae2 Mon Sep 17 00:00:00 2001 From: Aaron Harper Date: Wed, 5 Mar 2025 14:06:46 -0500 Subject: [PATCH 4/4] Bump version to 0.4.20 --- pkg/inngest/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/inngest/pyproject.toml b/pkg/inngest/pyproject.toml index 1ea9b44c..27a7c307 100644 --- a/pkg/inngest/pyproject.toml +++ b/pkg/inngest/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "inngest" -version = "0.4.20a0" +version = "0.4.20" authors = [{ name = "Inngest Inc.", email = "hello@inngest.com" }] description = "Python SDK for Inngest" readme = "README.md"