- Notifications
You must be signed in to change notification settings - Fork 1.2k
DSL: preserve the skip_empty
setting in to_dict()
recursive serializations #3041
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
Conversation
52d6cce
to 74c1dde
Compare @pquentin added a 2nd commit with a small adjustment to your attempt that does reproduce the issue. The 3rd commit contains the fix, which involves the plumbing to pass |
477b784
to 6c4f43d
Compare 6c4f43d
to 575927c
Compare skip_empty
setting in to_dict()
recursive serializations There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM. It does fix the issue.
(My approval does not count for GitHub as the original author of the PR.)
def _safe_serialize(self, data: Any, skip_empty: bool) -> Any: | ||
try: | ||
return self._serialize(data, skip_empty) | ||
except TypeError: | ||
# older method signature, without skip_empty | ||
return self._serialize(data) # type: ignore[call-arg] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this? Is this for third-party libraries that want to subclass Field
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed for people who created their own custom fields and use the old signature in their _serialize()
methods.
…lizations (#3041) (#3047) * Try reproducing DSL issue 1577 * better attempt to reproduce * preserve skip_empty setting in recursive serializations --------- (cherry picked from commit 4761d56) Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co> Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
…lizations (#3041) (#3046) * Try reproducing DSL issue 1577 * better attempt to reproduce * preserve skip_empty setting in recursive serializations --------- (cherry picked from commit 4761d56) Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co> Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
…lizations (#3041) (#3044) * Try reproducing DSL issue 1577 * better attempt to reproduce * preserve skip_empty setting in recursive serializations --------- (cherry picked from commit 4761d56) Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co> Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
…lizations (#3041) (#3045) * Try reproducing DSL issue 1577 * better attempt to reproduce * preserve skip_empty setting in recursive serializations --------- (cherry picked from commit 4761d56) Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co> Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
I wanted to fix elastic/elasticsearch-dsl-py#1577, but realized I wasn't able to reproduce it.