Skip to content

Use .IsLegacyEmptyRequest instead of checking that .Request is nil in codegen#3098

Merged
shreyas-goenka merged 5 commits intomainfrom
parthban-db/request-message-always-defined
Jun 26, 2025
Merged

Use .IsLegacyEmptyRequest instead of checking that .Request is nil in codegen#3098
shreyas-goenka merged 5 commits intomainfrom
parthban-db/request-message-always-defined

Conversation

@parthban-db
Copy link
Copy Markdown
Contributor

@parthban-db parthban-db commented Jun 22, 2025

Changes

Changes because of always defining request messages. There is a bug in the Code Generator that sets the request to nil if it has no fields. As we fix the generator, it changes the generated code. To keep the generated code the same, we need to add exceptions for already existing requests.
IsLegacyEmptyRequest returns true if the request has no fields and, for the above reason, is not rendered in the SDK.

This PR also removes TODO from the template, which adds noise to the diff. Also, we don't need it to remind us to implement short flags.

Why

We made a few changes in the Code generator that ensure that the request can never be nil. However, we cannot add the request to the existing interface. So, adding an exception for legacy commands.

Tests

Existing CI. Manually verified this change, only changed a few comments.

Copy link
Copy Markdown
Contributor

@pietern pietern left a comment

Choose a reason for hiding this comment

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

Can you revert the changes to .github and remove tagging.py?

We use a different location for tagging.py and don't use the NEXT_CHANGELOG detector.

@parthban-db parthban-db marked this pull request as draft June 23, 2025 13:45
@parthban-db parthban-db force-pushed the parthban-db/request-message-always-defined branch from 2f15d60 to 86e842a Compare June 24, 2025 13:26
@parthban-db parthban-db marked this pull request as ready for review June 25, 2025 08:31
func newList() *cobra.Command {
cmd := &cobra.Command{}

// TODO: short flags
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are these comments being added? Do you need to rebase?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because the TODO depends on the request being null, and it is never null from now on. It is just not rendered for legacy requests.

{{if $request }}// TODO: short flags

Copy link
Copy Markdown
Contributor

@shreyas-goenka shreyas-goenka left a comment

Choose a reason for hiding this comment

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

The template changes look good to me. We need to fix the // TODO being added though.

Comment thread .codegen/service.go.tmpl
var {{.CamelName}}Overrides []func(
*cobra.Command,
{{- if .Request }}
{{- if not .IsLegacyEmptyRequest }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you explain the semantics of .IsLegacyEmptyRequest in the PR description? For which fields will it be set.

@parthban-db parthban-db force-pushed the parthban-db/request-message-always-defined branch from 37d2683 to 379fe40 Compare June 25, 2025 11:00
@shreyas-goenka shreyas-goenka merged commit c4632f6 into main Jun 26, 2025
12 of 13 checks passed
@shreyas-goenka shreyas-goenka deleted the parthban-db/request-message-always-defined branch June 26, 2025 08:55
@shreyas-goenka shreyas-goenka changed the title Changes because of always defining request messages Use .IsLegacyEmptyRequest instead of checking that .Request is nil in codegen Jun 26, 2025
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.

3 participants