Skip to content

fix: DCI envelope support for disability registry search (#217)#303

Open
Tarekchehahde wants to merge 1 commit into
OpenSPP:19.0from
Tarekchehahde:fix/217-disability-dci-envelope-search
Open

fix: DCI envelope support for disability registry search (#217)#303
Tarekchehahde wants to merge 1 commit into
OpenSPP:19.0from
Tarekchehahde:fix/217-disability-dci-envelope-search

Conversation

@Tarekchehahde

@Tarekchehahde Tarekchehahde commented Jul 11, 2026

Copy link
Copy Markdown

Summary

  • Change disability/crvs/farmer /sync/search stub endpoints to accept DCIEnvelope (matching client integrations and /registry/sync/search).
  • Return a signed DCI on-search envelope via build_signed_envelope() with one search_response item per request item (multi-item batch no longer fails validation).
  • Update registry alias tests to use envelope payloads with 2 search items.

Contract changes (deliberate)

  • HTTP status for stub search responses changes 501 → 200; rejection is expressed DCI-style in the envelope and per-item rjct statuses.
  • Bare SearchRequest payloads (without a DCIEnvelope wrapper) now fail FastAPI validation with 422 instead of reaching the old 501 stub.

Test plan

  • ./spp test spp_dci_serverTestRegistryAliasStubs.test_search_stubs_return_per_item_rjct
  • POST multi-item DCI envelope to /disability/registry/sync/search returns 200 + signed per-item rjct (until disability module ships)

Related to #217

Merge order (vs security PR #325)

Per the cross-PR interaction analysis (2026-07-24): this PR and #325 both bump spp_dci_server to the identical 19.0.2.0.4 — that manifest line auto-merges with no conflict marker. Either merge order works (code is fully disjoint: this PR is router-level, #325 is middleware that runs before any router), but whichever merges second must deliberately re-bump to 19.0.2.0.5 and move its HISTORY bullet under the new heading.

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

Copy link
Copy Markdown

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 refactors the sync search endpoints for the Disability, Civil, and Farmer registries to accept and return DCIEnvelope wrappers, introducing a helper function _build_stub_search_envelope to generate unimplemented stub responses. It also updates the corresponding tests and replaces deprecated utcnow() calls with timezone-aware now(UTC). Feedback includes a recommendation to use the existing build_signed_envelope helper to reduce boilerplate and ensure proper signing, as well as a correction for an incorrect path in the disability_sync_notify docstring.

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 +73 to +94
our_sender_id = get_sender_id(env) or "openspp"
total_count = len(response_items)

callback_header = DCICallbackHeader(
version=request_envelope.header.version,
message_id=str(uuid.uuid4()),
message_ts=datetime.now(UTC),
action=f"on-{request_envelope.header.action}",
sender_id=our_sender_id,
receiver_id=request_envelope.header.sender_id,
total_count=total_count,
status="rjct",
status_reason_code=MsgHeaderStatusReasonCode.ACTION_NOT_SUPPORTED.value,
status_reason_message=not_implemented_message,
completed_count=0,
)

return DCIEnvelope(
signature="",
header=callback_header,
message=search_response.model_dump(mode="json", exclude_none=True),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Instead of manually constructing the DCICallbackHeader and returning an unsigned DCIEnvelope (with signature=""), you can leverage the existing build_signed_envelope helper from spp_dci.services.response_helpers. This reduces boilerplate, ensures consistency, and automatically signs the envelope if a signing key is configured in the environment.

    from odoo.addons.spp_dci.services.response_helpers import build_signed_envelope

    return build_signed_envelope(
        env=env,
        original_header=request_envelope.header,
        response_message=search_response.model_dump(mode="json", exclude_none=True),
        status_code="rjct",
        status_reason_code=MsgHeaderStatusReasonCode.ACTION_NOT_SUPPORTED.value,
        status_reason_message=not_implemented_message,
        completed_count=0,
    )

SPDCI-compliant Disability Registry notification endpoint.

Path: /disability/registry/sync/notify
Path: /disability/registry/sync/search

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The path in the docstring was incorrectly changed to /disability/registry/sync/search. Since this is the notification endpoint (disability_sync_notify), it should remain /disability/registry/sync/notify.

Suggested change
Path: /disability/registry/sync/search
Path: /disability/registry/sync/notify

@gonzalesedwin1123 gonzalesedwin1123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution — aligning the stub aliases with the DCIEnvelope schema used by the real search endpoints is a legitimate improvement, and we verified it works as described: we applied the diff to current 19.0 on a local instance, replayed the exact two-item payload from #217 against /disability/registry/sync/search, and got a well-formed on-search envelope with per-item rjct and preserved reference_id correlation. The full spp_dci_server suite also passes with the patch applied (332 tests, 0 failures).

That said, requesting changes for the points below.

1. This PR does not resolve #217 — please change Fixes #217 to Related to #217

This is the important one. The 500 reported in #217 was observed on the demo server (openspp-dci-demo-dr), which runs a disability search implementation that is not the stub this PR modifies (see the triage in #217 (comment) — the stub in this repo returns a deterministic 422/501 for those payloads and cannot 500). Merging with Fixes #217 would auto-close the issue while the actual bug persists on the deployment. The issue needs to stay open, so the PR description should link it as Related to #217.

2. Docstring regression in disability_sync_notify

The docstring path was changed from /disability/registry/sync/notify to /disability/registry/sync/search — this is the notify endpoint, so the original path was correct. (The Gemini review flagged this too.)

3. Reuse build_signed_envelope instead of hand-rolling the envelope

spp_dci.services.response_helpers.build_signed_envelope already constructs exactly this callback envelope (header, on-<action>, reason codes) and signs it with the server's active key. The new _build_stub_search_envelope duplicates that logic and always returns signature="". Signed responses matter here — the #217 reporter is specifically trying to verify response signatures. Please build the response via the existing helper.

4. Repo policy: version bump + changelog + README

Every code change to a module needs, in the same PR:

  • a patch bump of version in spp_dci_server/__manifest__.py (5-segment 19.0.x.y.z);
  • a readme/HISTORY.md fragment (OCA style, ### <version> newest-first);
  • regenerated README.rst / static/description/index.html (let CI's pre-commit job print the expected diff and apply it verbatim rather than regenerating locally).

CI will fail without these.

5. Document the deliberate contract changes in the PR description

The change flips two behaviors for all three registries (disability, crvs, farmer), and neither is mentioned in the description:

  • HTTP status for the stub response changes 501 → 200 (with the rejection expressed DCI-style in the envelope/per-item statuses) — we think this is the right call, but it should be stated as a deliberate decision;
  • bare SearchRequest payloads that previously received 501 now fail validation with 422. Blast radius is likely nil (integrating against a not-implemented stub is unlikely), but it's still a request-contract change and should be called out.

Happy to re-review once these are addressed — the core of the change is verified and welcome.

@Tarekchehahde

Copy link
Copy Markdown
Author

Thanks @gonzalesedwin1123 — addressed all five review points in 8b696d9:

  1. PR body now says Related to Disability DCI sync search returns HTTP 500 for multi-item search_request #217 (not Fixes).
  2. Restored notify docstring path to /disability/registry/sync/notify.
  3. Stub search responses now use build_signed_envelope() (signed callbacks).
  4. Version bumped to 19.0.2.0.4 + readme/HISTORY.md + README.rst / static/description/index.html.
  5. PR description documents the deliberate 501→200 and bare SearchRequest422 contract changes.

Ready for re-review.

Disability/crvs/farmer sync/search stubs now accept DCIEnvelope requests
and return signed per-item on-search envelopes via build_signed_envelope.
Bump to 19.0.2.0.4 with HISTORY/README updates. Related to OpenSPP#217.
@Tarekchehahde
Tarekchehahde force-pushed the fix/217-disability-dci-envelope-search branch from 8b696d9 to 36fc397 Compare July 20, 2026 13:57
@Tarekchehahde

Copy link
Copy Markdown
Author

@gonzalesedwin1123 Addressed all five review points:

  1. PR body now says Related to Disability DCI sync search returns HTTP 500 for multi-item search_request #217 (not Fixes).
  2. Restored notify docstring path to /disability/registry/sync/notify.
  3. Stub search responses now use build_signed_envelope() (signed callbacks).
  4. Version bumped to 19.0.2.0.4 + readme/HISTORY.md + README.rst / static/description/index.html.
  5. PR description documents the deliberate 501→200 and bare SearchRequest→422 contract changes.

Ready for re-review.

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.

2 participants