nazrulworld / fhir.resources

FHIR Resources https://www.hl7.org/fhir/resourcelist.html
https://pypi.org/project/fhir.resources/
Other
365 stars 104 forks source link

BundleEntryRequest validation error #125

Closed rppala3 closed 1 year ago

rppala3 commented 1 year ago

Description

I'm trying to compose a simple BundleEntryRequest object, but I'm facing a validation error. Apparently request.url is not set correctly.

What I Did

Code

from fhir.resources.bundle import BundleEntryRequest
from fhir.resources.fhirtypes import Code, Uri
request = BundleEntryRequest.construct()
request.method = Code('POST')
request.url = Uri('Task')
request.json()

Output

Unexpected exception formatting exception. Falling back to standard exception
Output exceeds the [size limit](command:workbench.action.openSettings?%5B%22notebook.output.textLineLimit%22%5D). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?520d467a-8d13-4374-9fc9-4898abadd1d6)
Traceback (most recent call last):
  File "pydantic[/main.py](https://file+.vscode-resource.vscode-cdn.net/main.py)", line 369, in pydantic.main.BaseModel.__setattr__
  File "[/Users/rp7935/.local/share/anaconda3/envs/python-3_11-ipynb/lib/python3.11/site-packages/fhir/resources/bundle.py](https://file+.vscode-resource.vscode-cdn.net/Users/rp7935/.local/share/anaconda3/envs/python-3_11-ipynb/lib/python3.11/site-packages/fhir/resources/bundle.py)", line 508, in validate_required_primitive_elements_2059
    raise ValidationError(errors, cls)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic.error_wrappers.ValidationError: 1 validation error for BundleEntryRequest
url
  none is not an allowed value (type=type_error.none.not_allowed)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "[/Users/rp7935/.local/share/anaconda3/envs/python-3_11-ipynb/lib/python3.11/site-packages/IPython/core/interactiveshell.py](https://file+.vscode-resource.vscode-cdn.net/Users/rp7935/.local/share/anaconda3/envs/python-3_11-ipynb/lib/python3.11/site-packages/IPython/core/interactiveshell.py)", line 3460, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "[/var/folders/m_/4rqz6xqd5619xxk5vxx688w8j8l2zw/T/ipykernel_15069/231493470.py](https://file+.vscode-resource.vscode-cdn.net/var/folders/m_/4rqz6xqd5619xxk5vxx688w8j8l2zw/T/ipykernel_15069/231493470.py)", line 5, in <module>
    request.method = Code('POST')
    ^^^^^^^^^^^^^^
  File "pydantic[/main.py](https://file+.vscode-resource.vscode-cdn.net/main.py)", line 371, in pydantic.main.BaseModel.__setattr__
pydantic.error_wrappers.ValidationError: 1 validation error for BundleEntryRequest
__root__ -> url
  none is not an allowed value (type=type_error.none.not_allowed)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
...
                  ^^^^^^^^^^^^^^^^^^
  File "[/Users/rp7935/.local/share/anaconda3/envs/python-3_11-ipynb/lib/python3.11/inspect.py](https://file+.vscode-resource.vscode-cdn.net/Users/rp7935/.local/share/anaconda3/envs/python-3_11-ipynb/lib/python3.11/inspect.py)", line 1081, in findsource
    raise OSError('could not get source code')
OSError: could not get source code
nazrulworld commented 1 year ago

Please have a look this issue, might it be related to yours https://github.com/nazrulworld/fhir.resources/issues/56

rppala3 commented 1 year ago

OK, thank you very much. I refactored the previous code like below and it works.

from fhir.resources.bundle import BundleEntryRequest
from fhir.resources.fhirtypes import Code, Uri
request = BundleEntryRequest.construct(
  method = Code('POST'),
  url = Uri('Task')
)
request.json()