Skip to content

fix(ers): Add pgx driver and marshal/unmarshal metadata correctly.#3672

Draft
c-r33d wants to merge 1 commit into
mainfrom
multi-ers-sql
Draft

fix(ers): Add pgx driver and marshal/unmarshal metadata correctly.#3672
c-r33d wants to merge 1 commit into
mainfrom
multi-ers-sql

Conversation

@c-r33d

@c-r33d c-r33d commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

Testing Instructions

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Database Driver Support: Added the pgx driver for PostgreSQL to the SQL provider, enabling improved database connectivity.
  • Data Normalization: Introduced a normalization utility to ensure consistent handling of struct values during entity resolution, specifically addressing claim and metadata processing.
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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f84cffc3-84d8-4a66-a7b6-0495189ea8ca

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch multi-ers-sql

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

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.

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.

Comment on lines +387 to +410
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
}
}

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.

high

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
}

Comment on lines 254 to +255
switch strings.ToLower(p.config.Driver) {
case "postgres":
case "postgres", "pgx":

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.

medium

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" }).

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 208.958049ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 102.080155ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 421.986007ms
Throughput 236.97 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 45.438862476s
Average Latency 453.041274ms
Throughput 110.04 requests/second

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • examples
  • otdfctl
  • sdk
  • service
  • lib/fixtures
  • tests-bdd

See the workflow run for details.

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.

1 participant