client-py
client-py copied to clipboard
in models strict=False does not turn off validation as expected
in models strict=False parameter does not turn off validation as I expected.
>>> import fhirclient.models.observation as O
>>> o = O.Observation(strict=False)
>>> o.as_json()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ehaas/Documents/testing/pyexcel/venv36/lib/python3.6/site-packages/fhirclient/models/fhirabstractresource.py", line 42, in as_json
js = super(FHIRAbstractResource, self).as_json()
File "/Users/ehaas/Documents/testing/pyexcel/venv36/lib/python3.6/site-packages/fhirclient/models/fhirabstractbase.py", line 297, in as_json
raise FHIRValidationError(errs)
fhirclient.models.fhirabstractbase.FHIRValidationError: {root}:
'Property "code" on <fhirclient.models.observation.Observation object at 0x1022975c0> is not optional, you must provide a value for it'
'Property "status" on <fhirclient.models.observation.Observation object at 0x1022975c0> is not optional, you must provide a value for it'
This is by design: the strict=False
skips validation during initialization. The instance does not remember this state, you have to use try-except
when using as_json()
.
I stumbled on the try except pattern, but that doesn't let me see the ill-formed or half baked json. For example, I'm creating an resource and want to inspect it halfway - how do I get a look a the json if I can't just .as_json it?
Eric
Eric M Haas, DVM, MS Health eData Inc 1183 Mountain View Circle, Napa, 94558 707.227.2608|Skype: haas.eric1 [email protected]
On Sun, Apr 29, 2018 at 8:20 PM, Pascal Pfiffner [email protected] wrote:
This is by design: the strict=False skips validation during initialization. The instance does not remember this state, you have to use try-except when using as_json().
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/smart-on-fhir/client-py/issues/50#issuecomment-385306703, or mute the thread https://github.com/notifications/unsubscribe-auth/AHEU6m3NgTG-DNHCxPWSLJ1XPeT47RM_ks5ttoMRgaJpZM4TsDTl .
Thanks for the response by the way.
Eric
Eric M Haas, DVM, MS Health eData Inc 1183 Mountain View Circle, Napa, 94558 707.227.2608|Skype: haas.eric1 [email protected]
On Tue, May 1, 2018 at 7:44 AM, Eric Haas [email protected] wrote:
I stumbled on the try except pattern, but that doesn't let me see the ill-formed or half baked json. For example, I'm creating an resource and want to inspect it halfway - how do I get a look a the json if I can't just .as_json it?
Eric
Eric M Haas, DVM, MS Health eData Inc 1183 Mountain View Circle, Napa, 94558 707.227.2608|Skype: haas.eric1 [email protected]
On Sun, Apr 29, 2018 at 8:20 PM, Pascal Pfiffner <[email protected]
wrote:
This is by design: the strict=False skips validation during initialization. The instance does not remember this state, you have to use try-except when using as_json().
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/smart-on-fhir/client-py/issues/50#issuecomment-385306703, or mute the thread https://github.com/notifications/unsubscribe-auth/AHEU6m3NgTG-DNHCxPWSLJ1XPeT47RM_ks5ttoMRgaJpZM4TsDTl .
It's not currently possible to create invalid JSON with as_json()
. Could consider extending that method with a strict=True
argument and not raising if strict is False
towards the end of the implementation. But I'm not sure I see the use-case, do you need to inspect the JSON before it's valid?
my case is literally
logging.Info('my resource foo looks like {}'.format(resource.as_json())
but on the other hand it is easy to work around. thiinking about it -I'd keep it the way it is.
Eric
Eric M Haas, DVM, MS Health eData Inc 1183 Mountain View Circle, Napa, 94558 707.227.2608|Skype: haas.eric1 [email protected]
On Tue, May 1, 2018 at 12:42 PM, Pascal Pfiffner [email protected] wrote:
It's not currently possible to create invalid JSON with as_json(). Could consider extending that method with a strict=True argument and not raising if strict is False towards the end of the implementation. But I'm not sure I see the use-case, do you need to inspect the JSON before it's valid?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/smart-on-fhir/client-py/issues/50#issuecomment-385768438, or mute the thread https://github.com/notifications/unsubscribe-auth/AHEU6qTOsBqW7anbgk4cyv6Ne7IflADBks5tuLqqgaJpZM4TsDTl .