-
Notifications
You must be signed in to change notification settings - Fork 105
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
Conversation
dbc4f82
to
dedb389
Compare
There was a problem hiding this 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]) |
There was a problem hiding this comment.
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
[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] |
f113ef0
to
e4fb4ff
Compare
I've done this now. |
eefd645
to
91a795e
Compare
7f50a06
to
bc6a24a
Compare
>>> _event_type_pascal_case_to_constant_case("NexusOperationScheduled") | ||
"NEXUS_OPERATION_SCHEDULED" | ||
""" | ||
return re.sub(r"([A-Z])", r"_\1", s).lstrip("_").upper() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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();
}
There was a problem hiding this comment.
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
) | ||
|
||
|
||
def _event_type_constant_case_to_pascal_case(s: str) -> str: |
There was a problem hiding this comment.
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.
def _event_type_constant_case_to_pascal_case(s: str) -> str: | |
def _constant_case_to_pascal_case(s: str) -> str: |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
4d25d2f
to
7899721
Compare
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:temporalio/sdk-go@a10de39
With this PR: