FirelyTeam / spark

Firely and Incendi's open source FHIR server
BSD 3-Clause "New" or "Revised" License
258 stars 166 forks source link

VersionId parsing from headers in Spark.Web does not support the Weak ETags specified in FHIR API #713

Open JeremiahSanders opened 5 months ago

JeremiahSanders commented 5 months ago

Describe the bug Per HL7 R4 documentation, Resource VersionId values, when included in headers, are considered "weak ETags" (source).

In the reference FhirController implementation, the header value is simply extracted as-is (without stripping off W/" and trailing "). Reference Spark.Web source.

NOTE: This is not a bug in the Spark package itself; rather it's a problem in the reference Spark.Web implementation.

This results in errors when performing version-aware updates. Spark rejects the request because the version from the request contains the weak ETag formatting.

To Reproduce

Steps to reproduce the behavior:

  1. Create a new FHIR resource of any desired type in your Spark FHIR server.
  2. Retrieve its current version.
  3. Modify it.
  4. Use Hl7.Fhir.R4 NuGet package and its FhirClient.UpdateAsync with versionAware parameter set to true to HTTP PUT the updated version (requires the server to use the Spark.Web code linked above).
  5. Receive a FHIR exception.

Expected behavior Expectation is that the update will be accepted if the submitted resource version matches current on the server.

Spark version

Operating system + Database

Container service / Cloud infrastructure:

Additional context I have successfully verified that Spark handles the version correctly if the header parsing is corrected. E.g., via use of a """^W/"(\d+)"$""" Regex to extract the id from the weak ETag.

kennethmyhra commented 5 months ago

Thanks for the report @JeremiahSanders, do you have a fix already in place that could be PR'ed?

JeremiahSanders commented 5 months ago

@kennethmyhra : Unfortunately, no, I don't have a PR-able fix.

However, after additional testing, I discovered that there is a problem with version-aware updates within FHIR transaction requests. (I submitted that separately, under #714 .) I mention that because there may be some aspect of that issue's resolution which might impact how this issue is resolved. I.e., my workaround of stripping the prefix and suffix from the header's value before submission to IFhirService.UpdateAsync(IKey,Resource) might conflict with whatever resolution is identified for #714 .