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

bug-1945553: Fix json encoding error with empty aggregations object #6882

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

relud
Copy link
Member

@relud relud commented Jan 31, 2025

for es8+ search results may contain an AggResponse object under the aggregations key, instead a missing attribute like in es1.4, so here we convert that empty object to a dict

@relud relud requested a review from a team as a code owner January 31, 2025 22:34
@biancadanforth biancadanforth self-assigned this Feb 3, 2025
@biancadanforth
Copy link
Contributor

@relud : I filed a bug for this issue, bug-1945553. Can you update your PR/ticket title before merging and attach the PR to the bug when you get a chance?

@relud relud changed the title Fix json encoding error with empty aggregations object bug-1945553: Fix json encoding error with empty aggregations object Feb 3, 2025
@relud relud force-pushed the relud-fix-json-agg-type branch from c9507b2 to edd3b50 Compare February 3, 2025 16:42
@relud relud force-pushed the relud-fix-json-agg-type branch from edd3b50 to 11279bf Compare February 3, 2025 17:26
Comment on lines 430 to 432
aggregations = getattr(results, "aggregations", {})
if aggregations:
if isinstance(aggregations, AggResponse):
aggregations = self.format_aggregations(aggregations)
Copy link
Contributor

@willkg willkg Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With ES 8, the results value either:

  1. does not have an aggregations attribute at all in which case the aggregations variable points to a {} value
  2. does have an aggregations attribute which points to a AggResponse object in which case, that gets run through format_aggregations() which returns a dict

That seems good to me.

aggregations points to a value with two very different types. We're not doing type checking, so it's just mildly not great. If we were to switch to type checking, then this would be more obviously not great.

@relud relud added this pull request to the merge queue Feb 4, 2025
Merged via the queue into main with commit 31134b4 Feb 4, 2025
1 check passed
@relud relud deleted the relud-fix-json-agg-type branch February 4, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants