-
Notifications
You must be signed in to change notification settings - Fork 800
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
Inconsistent handling of empty lists in Document partial updates. #1819
Labels
Category: Bug
Something isn't right
Comments
miguelgrinberg
added
Category: Question
Category: Bug
Something isn't right
and removed
Category: Question
labels
May 7, 2024
miguelgrinberg
added a commit
to miguelgrinberg/elasticsearch-dsl-py
that referenced
this issue
May 8, 2024
I was able to reproduce this easily. I think |
miguelgrinberg
added a commit
to miguelgrinberg/elasticsearch-dsl-py
that referenced
this issue
May 8, 2024
You're right; there is no reason to pass Thank you! |
miguelgrinberg
added a commit
to miguelgrinberg/elasticsearch-dsl-py
that referenced
this issue
May 10, 2024
miguelgrinberg
added a commit
to miguelgrinberg/elasticsearch-dsl-py
that referenced
this issue
May 17, 2024
miguelgrinberg
added a commit
that referenced
this issue
May 20, 2024
* Document.update() should accept fields set to None or empty Fixes #1819 * use refresh instead of wait loop
miguelgrinberg
added a commit
that referenced
this issue
May 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! At work we are currently developing an API that relies on Elasticsearch responses. Within our document mapping, we have defined multi-value fields, which we aim to represent as empty arrays (
[]
) in the API response when these fields are empty. When initially indexing the document, it successfully store empty lists into ES as[]
by passing these fields withskip_empty=False
.However, we are encountering an issue with partial updates. After updating a field to become empty, it is stored as
None
instead of[]
, even though we are passing the field values as[]
.The root cause appears to be within the current implementation of the
Document.update
method for partial document updates. This method prepares data for Elasticsearch by invoking theto_dict
method, which, by default, ignores empty fields. Consequently, empty lists are treated asNone
and updated accordingly.Proposed Fix:
To address this issue, I propose modifying the
update
method to acceptskip_empty=False
and passing this parameter to theto_dict
method. This adjustment will ensure that empty lists are included in the update payload as empty lists instead of being interpreted asNone
.Steps to Reproduce:
Document.update
method, passing multi-value fields as empty lists[]
.None
instead of remaining as empty lists.I am willing to contribute to fixing this issue if you believe it should be fixed in this way.
The text was updated successfully, but these errors were encountered: