Skip to content

Fixing incorrect 500 error on get export job status. - #5768

Open
v-isyamauchi-gh wants to merge 3 commits into
mainfrom
personal/v-isyamauchi/204452
Open

Fixing incorrect 500 error on get export job status.#5768
v-isyamauchi-gh wants to merge 3 commits into
mainfrom
personal/v-isyamauchi/204452

Conversation

@v-isyamauchi-gh

Copy link
Copy Markdown
Contributor

Description

Return 400 instead of 500 for export jobs with invalid resource types

When an $export job is created with an invalid _type parameter, the orchestrator now validates resource types before enqueuing child jobs. Invalid types cause the job to fail with 400 Bad Request instead of an unhandled ResourceNotFoundException that surfaced as 500 Internal Server Error.

Related issues

Addresses [issue #204452].

Bug 204452: Export Job returns 500 when customer enters invalid type.

Testing

Tested by adding UTs and E2E tests.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

@v-isyamauchi-gh v-isyamauchi-gh added this to the FY27\Q1\2wk\2wk05 milestone Aug 27, 2026
@v-isyamauchi-gh
v-isyamauchi-gh requested a review from a team as a code owner August 27, 2026 22:05
@v-isyamauchi-gh v-isyamauchi-gh added Bug Bug bug bug. No-Issue-Activity This issue is now considered stale and will be closed soon Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs No-PaaS-breaking-change No-ADR ADR not needed labels Aug 27, 2026
@v-isyamauchi-gh
v-isyamauchi-gh requested a lite review from Copilot August 27, 2026 22:05

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.

Pull request overview

This PR fixes an export failure mode where creating an $export job with an invalid _type later surfaced as a 500 Internal Server Error. It adds explicit resource-type validation in the export orchestrator so invalid types fail the job as a 400 Bad Request, and it adds unit/E2E coverage for the scenario.

Changes:

  • Add ISearchService.IsValidResourceType(...) and implement it for SQL Server and Cosmos search services.
  • Validate export job _type values in both SQL and Cosmos export orchestrator jobs before enqueuing/processing child work.
  • Add unit tests for the orchestrator validation and an E2E test that asserts the status endpoint returns 400 for invalid _type.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/Microsoft.Health.Fhir.Shared.Tests.Integration/Persistence/CosmosDbFhirStorageTestsFixture.cs Updates test fixture construction to match the updated Cosmos search service constructor.
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Export/ExportTests.cs Adds E2E test for invalid _type resulting in 400 BadRequest on status polling.
src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs Implements IsValidResourceType using the SQL model’s resource type map.
src/Microsoft.Health.Fhir.SqlServer/Features/Operations/Export/SqlExportOrchestratorJob.cs Adds resource type validation step before export orchestration continues.
src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Microsoft.Health.Fhir.Shared.Core.UnitTests.projitems Includes the new unit test file in the shared unit test project items.
src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Operations/Export/ExportOrchestratorJobTests.cs Adds unit tests for the orchestrator’s resource type validation behavior.
src/Microsoft.Health.Fhir.CosmosDb/Features/Search/FhirCosmosSearchService.cs Adds IModelInfoProvider dependency and implements IsValidResourceType for Cosmos.
src/Microsoft.Health.Fhir.CosmosDb/Features/Operations/Export/CosmosExportOrchestratorJob.cs Adds resource type validation step for Cosmos export orchestration.
src/Microsoft.Health.Fhir.Core/Features/Search/SearchService.cs Adds base implementation stub for IsValidResourceType on the abstract search service base.
src/Microsoft.Health.Fhir.Core/Features/Search/ISearchService.cs Adds the IsValidResourceType contract to the search service interface.
src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportOrchestratorJob.cs Introduces shared ValidateResourceTypes(...) helper used by orchestrators to fail invalid jobs with 400.

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

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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportOrchestratorJob.cs:103

  • JobExecutionException takes an isCustomerCaused flag; invalid _type values are user input errors, so this should be marked customer-caused. Keeping this as false can skew telemetry/alerts by treating a 400 as an internal failure.
                var message = $"Invalid resource type(s): {string.Join(", ", invalidTypes)}";
                record.FailureDetails = new JobFailureDetails(message, HttpStatusCode.BadRequest);
                throw new JobExecutionException(message, record, false);

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.81%. Comparing base (53e30b0) to head (0df0b1a).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5768      +/-   ##
==========================================
+ Coverage   78.79%   78.81%   +0.01%     
==========================================
  Files        1020     1020              
  Lines       37783    37801      +18     
  Branches     5754     5758       +4     
==========================================
+ Hits        29772    29792      +20     
+ Misses       6594     6592       -2     
  Partials     1417     1417              

see 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug Bug bug bug. No-ADR ADR not needed No-Issue-Activity This issue is now considered stale and will be closed soon No-PaaS-breaking-change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants