Skip to content
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

Example 5 and Encounter validation is failing #39

Closed
ytitov opened this issue Oct 27, 2020 · 4 comments
Closed

Example 5 and Encounter validation is failing #39

ytitov opened this issue Oct 27, 2020 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ytitov
Copy link

ytitov commented Oct 27, 2020

Greetings, I am investigating this library to use in a ETL step for a data integration and looking to create FHIR data structures. I've never used pydantic before so please forgive my ignorance :) Could I get some help with why this is failing?

  • fhir.resources version: commit: f35c98f (most recent)
  • Python version: 3.7.9
  • Operating System: Windows 10

Description

I am trying to create an encounter:

from fhir.resources.encounter import Encounter
e: Encounter = Encounter(**{"class": 'inpatient', "status": "planned"})

What I Did

Results in a confusing error. Especially since it is talking about "jsondecode" error.

Traceback (most recent call last):
  File "test.py", line 62, in <module>
    fetchsome(cur, handleRow, some=100)
  File "test.py", line 39, in fetchsome
    rowFunc(row)
  File "test.py", line 52, in handleRow
    e: Encounter = Encounter(**{"class": 'inpatient', "status": "planned"})
  File "...\lib\site-packages\fhir.resources-6.0.0b7.dev0-py3.7.egg\fhir\resources\fhirabstractmodel.py", line 126, in __init__
    BaseModel.__init__(__pydantic_self__, **data)
  File "pydantic\main.py", line 362, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Encounter
class -> __root__
  expected value at line 1 column 1: line 1 column 1 (char 0) (type=value_error.jsondecode; msg=expected value at line 1 column 1; doc=; pos=0; lineno=1; colno=1)

In addition to above Example 5 doesn't seem to work either:

from fhir.resources.organization import Organization
org = Organization.construct()

results in

Traceback (most recent call last):
  File "test.py", line 17, in <module>
    org = Organization.construct()
  File "...\lib\site-packages\fhir.resources-6.0.0b7.dev0-py3.7.egg\fhir\resources\fhirabstractmodel.py", line 386, in construct
    m, "__dict__", {**deepcopy(cls.__field_defaults__), **values}
AttributeError: type object 'Organization' has no attribute '__field_defaults__'
@nazrulworld nazrulworld added the good first issue Good for newcomers label Oct 27, 2020
@nazrulworld
Copy link
Owner

@ytitov first of all thanks a lot for reporting this issue.

  1. Encounter(**{"class": 'inpatient', "status": "planned"}) this obisouly validation error as class should be Coding type dict instead of string, for example Encounter(**{"class": {"code": 'inpatient'}, "status": "planned"}). But I am fully agree with you about confusing error message, I will work on it.

  2. I cannot reproduce this error, in my local (Mac + Pycharm environment), would be nice if can share a gist file.

@ytitov
Copy link
Author

ytitov commented Oct 28, 2020

@nazrulworld First, thanks for your responses.

  1. You're right, my object was invalid, but I really wish the error message made sense. Unfortunately I am not a python expert, just a user :)

  2. To replicate:

  • create a new environment (I used python 3.7.9 because that is the maximum stated supported version)
  • enter the environment, git clone master, and I tried two methods of installation (individually):
    • pip install -e .[all]
    • ./setup.py install
  • run the code as in example 5
from fhir.resources.organization import Organization
org = Organization.construct()

The resulting error:

$ python demo_fail.py
Traceback (most recent call last):
  File "demo_fail.py", line 2, in <module>
    org = Organization.construct()
  File "C:\Users\ytitov\workspace\fhir\kn-udm-to-fhir\fhir.resources\fhir\resources\fhirabstractmodel.py", line 386, in construct
    m, "__dict__", {**deepcopy(cls.__field_defaults__), **values}
AttributeError: type object 'Organization' has no attribute '__field_defaults__'
(venv_py37)

EDIT:
Just for good measure I did the same thing on my other PC which is running Arch Linux with python 3.8.3. Used code from master and installed that, still same error. If you still can't reproduce I can see if I can create a Dockerfile for you.

@nazrulworld nazrulworld added the bug Something isn't working label Oct 28, 2020
@nazrulworld
Copy link
Owner

nazrulworld commented Oct 28, 2020

@ytitov I can confirm that problem to be reproducible in my PC and I know why this is happing
https://pypi.org/project/pydantic/1.7/ so new pydantic has some breaking changes. use earlier version than 1.7 would solve this problem.
But I am looking forward to support pydantic 1.7

@ytitov
Copy link
Author

ytitov commented Oct 28, 2020

@nazrulworld looks like downgrading to pydantic 1.6.1 fixes my issue

nazrulworld added a commit that referenced this issue Oct 28, 2020
…aseModel

* Issue #39 pydantic 1.6.x, 1.7.x compabilities.
nazrulworld added a commit that referenced this issue Oct 28, 2020
…odel_validator is handled with proper error message.

* fixes mypy linting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants