Skip to content

fix(queue-events-producer): serialize object payloads as JSON - #4108

Open
mohanrajvenkatesan23-04 wants to merge 1 commit into
taskforcesh:masterfrom
mohanrajvenkatesan23-04:fix/issue-2984-publishevent-stringify
Open

fix(queue-events-producer): serialize object payloads as JSON#4108
mohanrajvenkatesan23-04 wants to merge 1 commit into
taskforcesh:masterfrom
mohanrajvenkatesan23-04:fix/issue-2984-publishevent-stringify

Conversation

@mohanrajvenkatesan23-04

Copy link
Copy Markdown
Contributor

Port Impact Checklist

  • Python – does this change need to be ported or documented in the Python library?
  • Elixir – does this change need to be ported or documented in the Elixir library?
  • PHP – does this change need to be ported or documented in the PHP library?

Why

Fixes #2984.

QueueEventsProducer.publishEvent pushed each value of the payload straight onto the XADD args array. Redis then coerces every arg to a string via .toString(). For plain objects that yields "[object Object]", so a payload like { eventName: 'name', nested: { object: 'hello' } } arrived on the consumer side as { eventName: 'name', nested: '[object Object]' } — the original structure was unrecoverable.

The user reported the issue on src/classes/queue-events-producer.ts line 43 and noted that JSON serialization is the natural fix.

How

  • src/classes/queue-events-producer.ts: when a value is a non-null object (plain object, array, class instance), JSON.stringify it before pushing onto the args array. Primitive values (strings, numbers, booleans) are left alone so existing publishers that already pass primitives observe no change.
  • This mirrors what the producer already does conceptually for the built-in progress / completed events: their payloads round-trip through JSON.stringify on the producer side and JSON.parse on the consumer side (src/classes/queue-events.ts).
  • The consumer side is intentionally not modified. Auto-parsing every value would risk mis-parsing user strings that happen to look like JSON. Consumers of object-typed custom events can call JSON.parse themselves on the field they expect.

Additional Notes (Optional)

  • New regression test in tests/events.test.ts (when publishing custom events › serializes nested object payloads as JSON) publishes a { object: 'hello' } payload and asserts the receiver gets a JSON-string that parses back to the original object. Before the fix the test fails with '[object Object]'.
  • No public API change; the type signature of publishEvent<T> is unchanged.
  • TypeScript / Node-only. No port work required.

QueueEventsProducer.publishEvent pushed nested object values straight
into XADD args, leaving Redis to coerce them via toString() — which
yields "[object Object]" for plain objects. The payload was therefore
unrecoverable on the consumer side.

Now non-primitive values are JSON.stringified before being pushed
onto the args array, mirroring the pattern already used for the
built-in `progress` and `completed` events. Primitives are passed
through unchanged so existing custom-event publishers see no
behavioural change. Consumers of object-typed custom events can
JSON.parse the value on receive (the consumer side intentionally
stays opt-in to avoid mis-parsing strings that happen to look like
JSON).

Fixes taskforcesh#2984
@manast
manast requested review from Copilot and roggervalf and removed request for Copilot July 15, 2026 18:09
@manast

manast commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: QueueEventsProducer - publishEvent does not stringify input

2 participants