Skip to content

Fix search name serialization to match entity reads - #502

Open
tkuhemiya wants to merge 1 commit into
LDFLK:mainfrom
tkuhemiya:themiya/fix-search-name-serialization-2402
Open

tkuhemiya wants to merge 1 commit into
LDFLK:mainfrom
tkuhemiya:themiya/fix-search-name-serialization-2402

Conversation

@tkuhemiya

Copy link
Copy Markdown

Fixes #477

Description

Search and get-one-entity both store the same name in Neo4j, for example Ministry of Health. They serialized it differently, so a decoder written for create/get failed on search.

Create and get return a nested object whose protobuf string starts with 0A12. Search returned a JSON string of {typeUrl, hex} whose hex was the raw UTF-8 (4D69) with no protobuf header. The search HTTP field is a string. It should be "Ministry of Health".

What changed

  1. Core ReadEntities packs the name with commons.CreateTimeBasedValue, the same helper ReadEntity already uses.
  2. The read API unpacks that protobuf string instead of calling toString() on the whole Any, so JSON name is the real text.

E2E search tests parsed name with json.loads and hex-decode because that matched the bug. They now assert the plain string. The old decode would fail after this fix.

Notes for reviewers

I moved the core mapping into entityFromGraphFilterResult so I could unit-test packing without Neo4j. Nothing else calls it. Only ReadEntities and two tests use it. The actual fix is packing with CreateTimeBasedValue instead of []byte(name). If you want that left inline in the loop, I can put it back.

I added two test files for reasons that are easy to undo:

  • cmd/server/service_test.go is fully commented out, so search name packing had no live test.
  • commons.ConvertStringToAny already existed and had no tests. That helper writes the 0A12 header.

I can drop the helper or merge the tests into existing files if that fits this repo better.

Happy to make any changes and iterate!

How we checked it

Ran MongoDB, Neo4j, Postgres, core, ingestion, and read with Docker Compose.

  • Core go test ./... passed, including the new packing tests.
  • Read API Ballerina: 10 passing, including testExtractValueAsStringReturnsPlainName.
  • Ingestion API Ballerina: 14 passing.
  • Live create and search for Ministry of Health:
    • create still returns framed bytes 0A124D696E6973747279206F66204865616C7468
    • search returns "name": "Ministry of Health"
  • Government search e2e (test_search_by_name and related tests) passed.

ReadEntities packed entity names as raw UTF-8 labeled as protobuf
StringValue, and the read API stringified that Any as JSON. Search
now packs names with the same StringValue framing as ReadEntity and
returns the plain decoded string.

Co-authored-by: Themiya <tkuhemiya@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 26, 2026 10:30
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: f3cd743f-ec88-4c9d-94df-dd6abc966beb


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.

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Fixes inconsistent search entity-name serialization by using protobuf StringValue framing and returning plain strings from the read API.

Changes:

  • Centralizes search-result entity mapping.
  • Corrects name packing and unpacking.
  • Updates unit and E2E tests.
File Description
opengin/​tests/​e2e/​test_orgchart_test.py Updates organization-chart assertions.
opengin/​tests/​e2e/​basic_read_tests.py Updates search assertions.
opengin/​tests/​e2e/​basic_core_tests.py Updates name assertions.
opengin/​read-api/​tests/​read_api_service_test.bal Tests plain-name extraction.
opengin/​read-api/​read_api_service.bal Unpacks string values.
opengin/​core-api/​commons/​utils_test.go Tests protobuf framing.
opengin/​core-api/​cmd/​server/​utils.go Adds corrected entity mapping and name serialization.
opengin/​core-api/​cmd/​server/​utils_test.go Tests search-result mapping.
opengin/​core-api/​cmd/​server/​service.go Uses the shared mapper for search results.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
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.

[Bug] Search Endpoint Returns Incorrectly Serialized 'name' Field

4 participants