Skip to content

Conversation

@wilfredmulenga
Copy link
Contributor

@wilfredmulenga wilfredmulenga commented Oct 24, 2025

  • Adds a new optional field Topics to UpdateProjectMedata gRPC method call.
  • Potential breaking change as this method will be expecting topics as an object with value values as below:
grpcurl -plaintext \
  -H "authorization: Bearer token" \
  -import-path server/schemas/internalapi/v1 \
  -proto schema.proto \
  -H "user-id: 01k6me4n1rnhsnvrrp1zweddz5" \
  -d '{"project_id": "01k8mj1mjtp1rjb8s4g6qg4r9b", "topics": {"values": ["3D", "visualization", "GIS", "mapping"]}}' \
  localhost:50051 \
  reearth.visualizer.v1.ReEarthVisualizer/UpdateProjectMetadata

Whilst current visualizer expects topics as an array as below:

grpcurl -plaintext \
  -H "authorization: Bearer token" \
  -import-path server/schemas/internalapi/v1 \
  -proto schema.proto \
  -H "user-id: 01k6me4n1rnhsnvrrp1zweddz5" \
  -d '{"project_id": "01k8mj1mjtp1rjb8s4g6qg4r9b", "topics": ["3D"]}' \
  localhost:50051 \
  reearth.visualizer.v1.ReEarthVisualizer/UpdateProjectMetadata

This will result in an error only when topics field is passed in the method and no error is it isn't. So the breaking change is minimal.

Refactors metadata update tests to include subtests for various
scenarios, such as empty, nil, and multiple topics. Improves
test clarity and robustness by isolating cases.

Updates server logic to handle empty topics arrays explicitly,
ensuring consistent behavior when topics are empty or nil.
@wilfredmulenga wilfredmulenga requested a review from pyshx as a code owner October 24, 2025 02:52
Copilot AI review requested due to automatic review settings October 24, 2025 02:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements explicit handling for empty topics arrays in project metadata updates, addressing a proto3 limitation where optional repeated fields cannot be distinguished from intentionally empty arrays. The solution uses a sentinel value (single empty string) to signal topic deletion while preserving backward compatibility.

Key Changes:

  • Added server-side logic to detect and handle the empty topics sentinel value (array with single empty string)
  • Refactored metadata update tests into isolated subtests covering nil, empty, normal, and multiple topics scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
server/internal/adapter/internalapi/server.go Adds logic to convert sentinel value [""] to empty array for topic deletion
server/e2e/proto_project_metadata_test.go Restructures tests into subtests for different topics scenarios (normal, empty, nil, multiple)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}
// A single empty string is used as a sentinel value to signal topic deletion.
// This distinguishes it from proto3's default empty array behavior.
if len(req.Topics) == 1 && req.Topics[0] == "" {
Copy link
Contributor

@soneda-yuya soneda-yuya Oct 28, 2025

Choose a reason for hiding this comment

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

@wilfredmulenga
I’d suggest wrapping this field in an optional message (like optional Topics topics) so we can clearly distinguish between “not provided” and “explicitly empty”. It’s easier to handle cases where we want to clear the list.

This might be a breaking change, so I’ll leave the final decision up to you.

now

  message UpdateRequest {
    repeated string topics = 1;
  }

can’t tell the difference between “not set” and “empty array,”
so we end up relying on sentinel values like [""] to represent clearing.

suggestion

message UpdateRequest {
  optional Topics topics = 1;
}

message Topics {
  repeated string values = 1;
}

With this structure, we can distinguish:
• topics not provided → no update
• topics.values empty → explicitly clear the list
• topics.values non-empty → replace with new values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Thats a great approach. I have implemented it

@wilfredmulenga wilfredmulenga changed the title feat(server): update server logic to handle empty topics arrays explicitly feat(server)!: update server logic to handle empty topics arrays explicitly Oct 28, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Adds logic to filter out duplicate and empty topic strings in project metadata updates, ensuring a clean and unique list of topics. Updates unit tests to validate this behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants