odmantic icon indicating copy to clipboard operation
odmantic copied to clipboard

Embedded Model Exclude None Not Functioning

Open pmcb99 opened this issue 1 year ago • 1 comments

Bug

Using 'exclude_none' in .update function does not work for fields in embedded models

Current Behavior

Create 'model' with embedded model in field. Use 'exclude_none' in 'model.update(*, exclude_none=True). Field with non-null value becomes null in embedded model.

Expected behavior

Fields in embedded model should not change from a non-null value to a null if exclude_none is set to True.

Environment

  • ODMantic version: odmantic==0.8.0

pmcb99 avatar Apr 18 '23 00:04 pmcb99

@art049 hey Arthur. I made a PR for this #355 . It uses a recursive function to avoid the patch object values overwriting the values we wish to keep, if they are None. This logic only happens if exclude_none is set to true. Let me know if there is any feedback, but the solution I wrote works for nested dictionaries and lists of nested dictionaries.

pmcb99 avatar Apr 19 '23 04:04 pmcb99