Closed chgl closed 3 years ago
First of all thanks a lot for your nice input! Let me explain why this happening:
validate_assignment = True
in the BaseModel class's meta config because we want to make sure the right value would be assigned to each field.validate_assignment
value is True, pydantic behind the scene calls any available pre/post root validator before it assigns field value (with validation).status
is required for Observation). NB: we are not using the required option inside field declaration intentionally because of support for primitive data type extensibility. For example, though status
is required, but if you use an extension for status
, then it becomes optional.construct()
might make a broken situation always if more than one fields are required.construct()
method for all cases.Thank you for the detailed explanation! The new validation support is incredibly helpful (although the initial migration was a bit painful:). Great work!
Is it OK if I create a PR and update the README.md's "Example: 5:" with a reference to this issue/your comment?
You are always welcome 🙏 to make any PR. Good luck!
I have a workaround for this: I use the constructor but with those parameters that are required.
my_bundle = Bundle.construct(type="message")
my_bundle.id = str(uuid.uuid4())
Description
It seems that the validation success depends on when
resource.id
is set - at least that's my interpretation for now. Is this expected behavior?What I Did
The following crashes with a validation error:
but switching
o.id
ando.status
around works fine: