Skip to content

Fixing bulk-delete on custom search parameters. #5026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

v-isyamauchi-gh
Copy link

Description

The PR will address an issue of the search parameter status going out of sync after $bulk-delete removes search parameter resources.

Related issues

Addresses [issue #121676].
Bug 121676: Hard delete custom search parameter not cleaning up all the data

Testing

Tested manually and also through adding E2E test.

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 CY25Q2/2Wk06 milestone Jun 17, 2025
@v-isyamauchi-gh v-isyamauchi-gh requested a review from a team as a code owner June 17, 2025 21:25
@v-isyamauchi-gh v-isyamauchi-gh added Bug Bug bug bug. 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 Open source This change is only relevant to the OSS code or release. labels Jun 17, 2025
@v-isyamauchi-gh
Copy link
Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@v-isyamauchi-gh
Copy link
Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@v-isyamauchi-gh
Copy link
Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@v-isyamauchi-gh
Copy link
Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

{
searchParameterStatusList.Add(new ResourceSearchParameterStatus
_logger.LogError(ex, "The search parameter '{Uri}' not supported.", uri);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment for what could cause this exception and why we want to sometimes ignore it? I think it will be good to have the record of why this was added.

Copy link
Author

Choose a reason for hiding this comment

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

Added the comment (Please review and let me know if it needs to be corrected.)

SearchParameterInfo typeLookup = null;
if (_searchParameterDefinitionManager.TryGetSearchParameter(searchParameter.Uri.OriginalString, out urlLookup))
{
_searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
urlLookup
may be null at this access as suggested by
this
null check.

Copilot Autofix

AI 3 days ago

To fix the issue, we need to ensure that urlLookup is not null before dereferencing it on line 256. This can be achieved by adding a null check for urlLookup before accessing its BaseResourceTypes property. If urlLookup is null, the code should skip the operation or handle the case appropriately.

The fix involves:

  1. Adding a null check for urlLookup before line 256.
  2. Ensuring that the logic gracefully handles the case where urlLookup is null.
Suggested changeset 1
src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs b/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs
--- a/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs
+++ b/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs
@@ -255,3 +255,6 @@
                 {
-                    _searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);
+                    if (urlLookup != null)
+                    {
+                        _searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);
+                    }
                 }
EOF
@@ -255,3 +255,6 @@
{
_searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);
if (urlLookup != null)
{
_searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
SearchParameterInfo typeLookup = null;
if (_searchParameterDefinitionManager.TryGetSearchParameter(searchParameter.Uri.OriginalString, out urlLookup))
{
_searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
urlLookup
may be null at this access as suggested by
this
null check.

Copilot Autofix

AI 3 days ago

To fix the issue, we need to ensure that urlLookup is not null before dereferencing it on line 315. This can be achieved by adding a null check for urlLookup before accessing its BaseResourceTypes property. If urlLookup is null, the code should skip the operation or handle it appropriately.

The fix involves:

  1. Adding a null check for urlLookup before line 315.
  2. Ensuring that the logic gracefully handles the case where urlLookup is null.
Suggested changeset 1
src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs b/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs
--- a/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs
+++ b/src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/SearchParameterOperations.cs
@@ -314,3 +314,6 @@
                 {
-                    _searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);
+                    if (urlLookup != null && urlLookup.BaseResourceTypes.Count > 0)
+                    {
+                        _searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);
+                    }
                 }
EOF
@@ -314,3 +314,6 @@
{
_searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);
if (urlLookup != null && urlLookup.BaseResourceTypes.Count > 0)
{
_searchParameterDefinitionManager.TryGetSearchParameter(urlLookup.BaseResourceTypes[0], urlLookup.Code, false, out typeLookup);
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
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. Open source This change is only relevant to the OSS code or release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants