Fix list projects to return NumericId and FriendlyName#431
Conversation
|
@goccy Can you review this when you have a chance? |
|
Thank you for your contribution ! LGTM 👍 |
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #391 by adding the missing NumericId and FriendlyName fields to the projects.list API endpoint response. The Google Cloud BigQuery Python client requires these fields to be present in the ProjectListProjects response, and their absence was causing a KeyError when calling client.list_projects().
Changes:
- Added
NumericIdfield (assigned as sequential 1-indexed integer based on loop position) - Added
FriendlyNamefield (defaults to project ID) - Added test coverage for the
projects.listendpoint to verify the presence of all required fields
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| server/handler.go | Modified projectsListHandler.Handle to populate NumericId and FriendlyName fields in the project list response |
| server/server_test.go | Added TestListProjects to verify the endpoint returns projects with all required fields (Id, NumericId, FriendlyName) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| projectList = append(projectList, &bigqueryv2.ProjectListProjects{ | ||
| Id: p.ID, | ||
| Id: p.ID, | ||
| NumericId: uint64(i + 1), |
There was a problem hiding this comment.
The NumericId assignment is non-deterministic because the SQL query in FindAllProjects (line 232 of internal/metadata/repository.go) does not include an ORDER BY clause. This means the order of projects can vary between calls, causing the same project to receive different NumericIds on different invocations. Consider either: (1) adding an ORDER BY id clause to the FindAllProjects query to ensure consistent ordering, or (2) using a hash function on the project ID to generate a stable numeric ID, or (3) storing the numeric ID in the database.
| for _, p := range projectList.Projects { | ||
| if p.Id == "" { | ||
| t.Error("Id should not be empty") | ||
| } | ||
| if p.NumericId == 0 { | ||
| t.Error("NumericId should not be zero") | ||
| } | ||
| if p.FriendlyName == "" { | ||
| t.Error("FriendlyName should not be empty") | ||
| } | ||
| } |
There was a problem hiding this comment.
The test should verify that NumericId assignments are stable across multiple calls to the list projects endpoint. Consider adding an assertion that calls the endpoint twice and verifies each project receives the same NumericId in both calls. This would catch the non-deterministic ordering issue.
Fix projects.list to return NumericId and FriendlyName
Fixes #391
Problem
The
projects.listAPI endpoint only returns theidfield for each project, but the Google Cloud BigQuery Python client expectsnumericIdandfriendlyNamefields to also be present. This causes aKeyErrorwhen callingclient.list_projects().Reproduction
Start the emulator:
Run the following Python code:
Result:
Fix
Add the missing
NumericIdandFriendlyNamefields to theProjectListProjectsresponse:NumericIdis assigned a sequential integer (1-indexed)FriendlyNamedefaults to the project ID