Skip to content

Nexus bug fix: accept event type name casing variant used by latest server #953

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

Merged
merged 23 commits into from
Jul 10, 2025

Conversation

dandavison
Copy link
Contributor

@dandavison dandavison commented Jul 9, 2025

The Nexus link conversion was assuming that the server sends an event type name formatted as CONSTANT_CASE with the EVENT_TYPE_ prefix. However, the latest server sends PascalCase without the prefix:

18:42:52 [ WARNING] Failed to parse event type from Nexus link URL query parameters: Link(url='temporal:///namespaces/default/workflows/367a1427-1d37-470b-a761-30fbd12e7ed7/0197f15b-2963-79d7-814d-352bba12e672/hist
ory?eventID=5&eventType=NexusOperationScheduled&referenceType=EventReference', type='temporal.api.common.v1.Link.WorkflowEvent') (Enum EventType has no value defined for name 'NEXUS_OPERATION_SCHEDULED') (_operatio
n_context.py:550)

temporalio/sdk-go@a10de39

With this PR:

# CLI 1.3.1, Server 1.27.0
#
# send inbound links with StartWorkflow request:
# _query_params_to_event_reference:
# eventID=5&eventType=EVENT_TYPE_NEXUS_OPERATION_SCHEDULED&referenceType=EventReference
# ->
# event_id: 5, event_type: EVENT_TYPE_NEXUS_OPERATION_SCHEDULED

# add outbound links to StartWorkflow response:
# _event_reference_to_query_params:
# event_id: 1, event_type: EVENT_TYPE_WORKFLOW_EXECUTION_STARTED
#  ->
# eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference


# CLI 1.4.0 (Server 1.28.0)
#
# send inbound links with StartWorkflow request:
# _query_params_to_event_reference:
# eventID=5&eventType=NexusOperationScheduled&referenceType=EventReference
# ->
# event_id: 5, event_type: EVENT_TYPE_NEXUS_OPERATION_SCHEDULED

# add outbound links to StartWorkflow response:
# _event_reference_to_query_params:
# event_id: 1, event_type: EVENT_TYPE_WORKFLOW_EXECUTION_STARTED
#  ->
# eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference

@dandavison dandavison requested a review from a team as a code owner July 9, 2025 22:52
Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also would want to convert to pascal case when you generate a link.

f"Expected Nexus link URL query parameter referenceType to be EventReference but got: {reference_type}"
)
# event type
[raw_event_type_name] = query_params.get(LINK_EVENT_TYPE_PARAM_NAME, [None])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could save the list construction in the happy path

Suggested change
[raw_event_type_name] = query_params.get(LINK_EVENT_TYPE_PARAM_NAME, [None])
[raw_event_type_name] = query_params.get(LINK_EVENT_TYPE_PARAM_NAME) or [None]

@dandavison
Copy link
Contributor Author

You also would want to convert to pascal case when you generate a link.

I've done this now.

@dandavison dandavison marked this pull request as draft July 10, 2025 14:37
@dandavison dandavison marked this pull request as ready for review July 10, 2025 16:07
>>> _event_type_pascal_case_to_constant_case("NexusOperationScheduled")
"NEXUS_OPERATION_SCHEDULED"
"""
return re.sub(r"([A-Z])", r"_\1", s).lstrip("_").upper()
Copy link
Contributor Author

@dandavison dandavison Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incidentally, there are a couple of bugs in the TS versions of these functions (e.g. \b in a character class is backspace I believe, not word boundary, and the utilities would fail on ContainsAOneLetterWord). Probably doesn't affect their actual usage in practice on event type names. cc @mjameswh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\b is a word boundary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I do see how this case isn't covered in TS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works though and is more compact:

function pascalCaseToConstantCase(s: string) {
  return s.replace(/\B[A-Z]/g, (m) => `_${m[0]}`).toUpperCase();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\b in a character class is backspace I believe, not word boundary

\b is a word boundary.

Not in a character class, which is how it's being used in sdk-typescript

console.log('a'.match(/\b/))   // ""
console.log('a'.match(/[\b]/)) // null

@dandavison dandavison requested a review from bergundy July 10, 2025 16:38
)


def _event_type_constant_case_to_pascal_case(s: str) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a generic helper, nothing to do with event types.

Suggested change
def _event_type_constant_case_to_pascal_case(s: str) -> str:
def _constant_case_to_pascal_case(s: str) -> str:

Copy link
Contributor Author

@dandavison dandavison Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to qualify their names with the event_type prefix to avoid any implication that they are suitable for use as general case conversion utilities. For example, they have undefined behavior currently if the input doesn't match the expectation that it is already in the expected input form, and the tests don't cover trailing/leading underscores, etc.

>>> _event_type_pascal_case_to_constant_case("NexusOperationScheduled")
"NEXUS_OPERATION_SCHEDULED"
"""
return re.sub(r"([A-Z])", r"_\1", s).lstrip("_").upper()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I do see how this case isn't covered in TS.

return re.sub(r"(\b|_)([a-z])", lambda m: m.groups()[1].upper(), s.lower())


def _event_type_pascal_case_to_constant_case(s: str) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@dandavison dandavison merged commit 31c1c41 into temporalio:main Jul 10, 2025
47 of 51 checks passed
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.

2 participants