Stream: implementers
Topic: Batch validation
RB Johnson (Jun 29 2021 at 16:05):
When parsing a Batch Bundle request how should validation be handled?
I see two ways this could be handled:
- Validation is run on the whole Batch request to ensure it is valid FHIR and a validation error fails the entire batch.
- Validation is run on the Bundle component of the Batch request to ensure it is a valid Batch Bundle and then each request in the Batch is validated independently. A validation error on the Bundle fails the Batch, but validation errors on the included requests only fail that part of the Batch.
Is there a consensus on which is correct behavior?
RB Johnson (Jun 29 2021 at 16:15):
Grahame's and Vonk's test servers and the Azure API for FHIR fail the entire Batch for a validation error in one of the requests. If this is the consensus among implementers, can it be reflected in the spec?
Lloyd McKenzie (Jun 29 2021 at 17:09):
It's up to a server to decide how (and if) it wants to validate. Some types of errors may prevent parsing of the instance at all. Depending on parsing strategy, it may be possible to process parts of the batch prior to detecting the bad syntax. Right now, we assume that the entire thing is parsed before any responses are provided because a conformant (non global fail) response requires a matching number of entries in the response Bundle, and you can't really do that unless you've at least been able to parse the whole thing. Beyond that, whether you validate everything before you start processing or validate each entry or do a mixture is up to you.
Paul Church (Jun 29 2021 at 17:45):
I agree that failing the entire batch for any validation error is generally the way to go - for one thing, can you really check that there are no inter-dependencies among batch entries if some of them aren't even valid?
Eric Haas (Jun 29 2021 at 17:51):
Paul Church said:
I agree that failing the entire batch for any validation error is generally the way to go - for one thing, can you really check that there are no inter-dependencies among batch entries if some of them aren't even valid?
The Spec says:
The actions may be performed independently as a "batch", or as a single atomic "transaction" where the entire set of changes succeed or fail as a single entity
Eric Haas (Jun 29 2021 at 17:51):
so my expectation would be counter to @Paul Church
David Pyke (Jun 29 2021 at 17:51):
Yes, usually batch bundles are independent events within and transactions are atomic and all fail if one fails.
David Pyke (Jun 29 2021 at 17:53):
So, you can validate a batch in parallel and fail those (with resulting status) that are invalid and a transaction bundle is validated all at once and then the transactions processed
Paul Church (Jun 29 2021 at 17:58):
As far as I'm concerned, a Bundle is a single resource that either passes or fails validation.
If some contained resource fails validation, its container can't go on as if it was a valid resource. Bundles are no different.
David Pyke (Jun 29 2021 at 17:59):
Batch and Transaction Bundles are envelopes. The Bundle itself needs to be valid but if the entry resource fails, the rest of the batch entries can still be processed
Paul Church (Jun 29 2021 at 18:10):
Are there any implementations that will process some of the batch entries when some don't validate?
Vassil Peytchev (Jun 29 2021 at 18:12):
I agree that failing the entire batch for any validation error is generally the way to go - for one thing, can you really check that there are no inter-dependencies among batch entries if some of them aren't even valid?
Batch rules are quite prescriptive and strongly lean towards independent processing of each entry, and not failing the entire batch, but I don't know if they are practical:
For a batch, there SHALL be no interdependencies between the different entries in the Bundle that cause change on the server. The success or failure of one change SHOULD not alter the success or failure or resulting content of another change. Servers SHOULD validate that this is the case. Note that it is considered that servers execute the batch in the same order as that specified below for transactions, though the order of execution should not matter given the previous rule.
References within a Bundle.entry.resource to another Bundle.entry.resource that is being created within the batch are considered to be non-conformant.
When processing the batch, the HTTP response code is 200 Ok if the batch was processed correctly, regardless of the success of the operations within the Batch. To determine the status of the operations, look inside the returned Bundle. A response code on an entry of other than 2xx (200, 202 etc) indicates that processing the request in the entry failed.
Eric Haas (Jun 29 2021 at 18:16):
If you want to write A,B and C in a batch bundle to serverX and server will only accept A, but A references B and C I assume for referential integitry reasons you would fails the whole batch bundle. but what if A,B,C were completely independent of each other?
David Pyke (Jun 29 2021 at 18:17):
References within a Bundle.entry.resource to another Bundle.entry.resource that is being created within the batch are considered to be non-conformant.
David Pyke (Jun 29 2021 at 18:17):
They must be completely independent
Grahame Grieve (Jun 29 2021 at 18:33):
the batch itself is a bundle; servers are OK to reject the entire batch if the bundle is not valid
Last updated: Apr 12 2022 at 19:14 UTC