Skip to content

fix: suppress obsolete warning when enumerating a deprecated resources field - #1017

Merged
robertvoinescu-work merged 1 commit into
mainfrom
robertvoinescu/deprecated-paged-resource
Oct 23, 2026
Merged

robertvoinescu-work merged 1 commit into
mainfrom
robertvoinescu/deprecated-paged-resource

Conversation

@robertvoinescu-work

@robertvoinescu-work robertvoinescu-work commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

b/543020713

When a paginated method's resources field is marked deprecated, the generated code hits a deprecated warning. In this case the method should not be deprecated and we should disable the warning on the repeated field while we are using this implementation.

As a concrete example, for Apps.V1 chat the Spaces field for SearchSpacesResponse is deprecated and will be replaced with the new Results field. But while Spaces exists it is the lowest numbered repeated field so it will be used for pagination. We do not mark the enumeration methods as obsolete as what is obsolete is our implementation (using Spaces.GetEnumerator instead of the new repeated Results.Enumerator field to get the enumerator - see below), once Spaces field is removed from the proto our implementation will become the following and not throw (validated):

public scg::IEnumerator<Types.SearchSpaceResult> GetEnumerator() => Results.GetEnumerator();

Validation

  • I've regenerated all libraries and the only changes present where those for Apps Chat V1 fixing the issue:
diff --git a/apis/Google.Apps.Chat.V1/Google.Apps.Chat.V1/ChatServiceClient.g.cs b/apis/Google.Apps.Chat.V1/Google.Apps.Chat.V1/ChatServiceClient.g.cs
--- a/apis/Google.Apps.Chat.V1/Google.Apps.Chat.V1/ChatServiceClient.g.cs
+++ b/apis/Google.Apps.Chat.V1/Google.Apps.Chat.V1/ChatServiceClient.g.cs
@@ -19286,7 +19286,9 @@
     public partial class SearchSpacesResponse : gaxgrpc::IPageResponse<Space>
     {
         /// <summary>Returns an enumerator that iterates through the resources in this response.</summary>
+#pragma warning disable CS0612
         public scg::IEnumerator<Space> GetEnumerator() => Spaces.GetEnumerator();
+#pragma warning restore CS0612
 
         sc::IEnumerator sc::IEnumerable.GetEnumerator() => GetEnumerator();
     }

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the API generator to mark a paginated method and its enumerators as deprecated if its underlying resources field is deprecated. It also updates the snippet generator to wrap page iterations in obsolete warning suppressions (#pragma warning disable CS0612) when the method is deprecated. Tests, fakes, and generated snippets have been added to verify this behavior. There are no review comments to address, so I have no feedback to provide.

@robertvoinescu-work robertvoinescu-work changed the title b/543020713 fix: Handle deprecated resources in paginated methods Oct 20, 2026
@robertvoinescu-work robertvoinescu-work changed the title fix: Handle deprecated resources in paginated methods fix: mark paginated methods obsolete when the resources field is deprecated Oct 20, 2026
@robertvoinescu-work
robertvoinescu-work force-pushed the robertvoinescu/deprecated-paged-resource branch from 231c3e1 to cc0e95d Compare October 20, 2026 23:18
@robertvoinescu-work
robertvoinescu-work marked this pull request as ready for review October 20, 2026 23:36
@robertvoinescu-work
robertvoinescu-work requested a review from a team as a code owner October 20, 2026 23:36
@robertvoinescu-work
robertvoinescu-work force-pushed the robertvoinescu/deprecated-paged-resource branch from cc0e95d to 274b568 Compare October 21, 2026 17:52
@robertvoinescu-work robertvoinescu-work changed the title fix: mark paginated methods obsolete when the resources field is deprecated fix: suppress obsolete warning when enumerating a deprecated resources field Oct 21, 2026
SyncGrpcType = Typ.Generic(typeof(GrpcPagedEnumerable<,,>), RequestTyp, ResponseTyp, ResourceTyp);
AsyncGrpcType = Typ.Generic(typeof(GrpcPagedAsyncEnumerable<,,>), RequestTyp, ResponseTyp, ResourceTyp);
ResourcesFieldName = responseResourceField.CSharpPropertyName();
IsResourcesFieldDeprecated = responseResourceField.GetOptions()?.Deprecated ?? false;

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.

I see there's an extension method on the FieldDescriptor class similar to this except it's also checking if the containing type is deprecated:

        public static bool IsDeprecated(this FieldDescriptor desc) =>
            (desc?.GetOptions()?.Deprecated ?? false) || IsDeprecated(desc?.ContainingType);

Is that something we'll need here?

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.

Good call out, but it's not required in this case. That would result in the following getting wrapped:

+#pragma warning disable CS0612
        sc::IEnumerator sc::IEnumerable.GetEnumerator() => GetEnumerator())
+#pragma warning restore CS0612

Although this method doesn't need to get wrapped as it doesn't reference the obsolete type.

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.

I see it's being used now, did you find something that caused a change of heart?

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.

Yes sorry forgot to update here. I was wrong totally wrong in my initial comment - I ran it and that doesn't actually get wrapped 🤦 . So I went ahead and used IsDeprecated. Thanks for pointing it out.

@robertvoinescu-work
robertvoinescu-work force-pushed the robertvoinescu/deprecated-paged-resource branch from 274b568 to 77bbaab Compare October 21, 2026 20:35
/// <param name="request">The request object containing all of the parameters for the API call.</param>
/// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
/// <returns>A pageable sequence of <see cref="Response"/> resources.</returns>
public virtual gax::PagedEnumerable<DeprecatedResourcesFieldPaginatedResponse, Response> DeprecatedResourcesFieldPaginatedMethod(PaginatedRequest request, gaxgrpc::CallSettings callSettings = null) =>

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.

Ideally API teams would mark this method as deprecated when they mark the list property deprecated. But I don't' think that's an easy thing for us to do, not sure if it's our decision to make. Just leaving this comment for posterity.

@robertvoinescu-work
robertvoinescu-work merged commit 7437d21 into main Oct 23, 2026
15 of 16 checks passed
@robertvoinescu-work
robertvoinescu-work deleted the robertvoinescu/deprecated-paged-resource branch October 23, 2026 20:54
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