fix(ers): Add pgx driver and marshal/unmarshal metadata correctly.#3672
fix(ers): Add pgx driver and marshal/unmarshal metadata correctly.#3672c-r33d wants to merge 1 commit into
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the entity resolution service by adding support for the pgx PostgreSQL driver and implementing a robust normalization mechanism for struct values. These changes ensure better compatibility with database drivers and improve data integrity when processing claims and metadata. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. The driver is set for the pgx, To keep all the data in flux. With values now clean, And logic serene, We've squashed all the nasty old bugs. Footnotes
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request replaces the legacy PostgreSQL driver with the pgx driver in the SQL provider and introduces a normalizeStructValue helper to normalize claims and metadata before protobuf conversion. Feedback highlights that removing the postgres driver import will cause runtime failures for existing configurations unless postgres is mapped to pgx during initialization. Additionally, the normalizeStructValue implementation is limited and could cause protobuf conversion failures for unsupported slice or map types; using a JSON round-trip is recommended for robust normalization.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| func normalizeStructValue(value interface{}) interface{} { | ||
| switch typed := value.(type) { | ||
| case []string: | ||
| normalized := make([]interface{}, len(typed)) | ||
| for i, item := range typed { | ||
| normalized[i] = item | ||
| } | ||
| return normalized | ||
| case []interface{}: | ||
| normalized := make([]interface{}, len(typed)) | ||
| for i, item := range typed { | ||
| normalized[i] = normalizeStructValue(item) | ||
| } | ||
| return normalized | ||
| case map[string]interface{}: | ||
| normalized := make(map[string]interface{}, len(typed)) | ||
| for key, item := range typed { | ||
| normalized[key] = normalizeStructValue(item) | ||
| } | ||
| return normalized | ||
| default: | ||
| return value | ||
| } | ||
| } |
There was a problem hiding this comment.
The current implementation of normalizeStructValue only handles []string, []interface{}, and map[string]interface{}. If a provider returns other slice types (such as []int, []bool, []float64) or other map types (such as map[string]string), they will fall through to the default case and be returned as-is. This will cause structpb.NewStruct to fail with an error because it only supports []interface{} for lists and map[string]interface{} for structs.
Using a JSON round-trip is a highly robust and clean way to normalize any arbitrary slice, map, or struct into structpb-compatible types without needing to manually handle every possible type combination.
func normalizeStructValue(value interface{}) interface{} {
if value == nil {
return nil
}
bytes, err := json.Marshal(value)
if err != nil {
return value
}
var normalized interface{}
if err := json.Unmarshal(bytes, &normalized); err != nil {
return value
}
return normalized
}| switch strings.ToLower(p.config.Driver) { | ||
| case "postgres": | ||
| case "postgres", "pgx": |
There was a problem hiding this comment.
Since the github.com/lib/pq driver import was removed in this PR, calling sql.Open("postgres", connStr) will fail at runtime with an unknown driver error if a user has postgres configured as their driver.
To support existing configurations seamlessly, consider mapping postgres to pgx when calling sql.Open in NewProvider (e.g., driver := config.Driver; if driver == "postgres" { driver = "pgx" }).
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
|
Proposed Changes
Checklist
Testing Instructions