Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Fix: [MongoDB Connector] Missing aggregation pipeline crashes sync job #495

Merged
merged 3 commits into from
Dec 2, 2022

Conversation

timgrein
Copy link
Contributor

@timgrein timgrein commented Dec 2, 2022

Closes https://github.com/elastic/enterprise-search-team/issues/3487

We now check if a pipeline is nil and set it to an empty array, if that's the case, so the sync job won't crash.

Checklists

Pre-Review Checklist

  • Covered the changes with automated tests
  • Tested the changes locally

…we should default to an empty pipeline (as it's valid according to the filtering validation) so the sync job doesn't crash (MongoDB Ruby client doesn't provide a default parameter for the pipeline, only for options).
options = extract_options(aggregate)

if !pipeline.nil? && pipeline.empty? && !options.present?
if !pipeline.present? && !options.present?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it doesn't make sense to use present? and empty? will be enough. You have an inline if-statement in line 156 so there is no way that pipeline can be nil.

The same applies to options. You just need to make sure that you have the right object type to respond to .empty? method.

Both suggestions are optional because I just advocate stopping the usage of ActiveSupport lib :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes totally sense, adjusted it 👍 What's the rationale behind stopping to use ActiveSupport?

Copy link
Contributor

@vidok vidok Dec 2, 2022

Choose a reason for hiding this comment

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

What's the rationale behind stopping to use ActiveSupport?

ActiveSupport is a part of RubyOnRails framework where performance and clean code are not super important (not saying it's bad). A recent example was HashWithIndifferentAccess which adds unnecessary overhead.

I don't like extending the language without any reasonable need because this kind of libs often brings overhead.

@timgrein timgrein requested a review from vidok December 2, 2022 14:59
@timgrein timgrein merged commit bc7a97e into main Dec 2, 2022
@timgrein timgrein deleted the tim/empty-aggregation-pipeline-crashes-sync-job branch December 2, 2022 16:25
github-actions bot pushed a commit that referenced this pull request Dec 2, 2022
#495)

When a pipeline is nil (not specified in the advanced rules UI) we should default to an empty pipeline (as it's valid according to the filtering validation) so the sync job doesn't crash (MongoDB Ruby client doesn't provide a default parameter for the pipeline, only for options).
@github-actions
Copy link

github-actions bot commented Dec 2, 2022

💚 Backport PR(s) successfully created

Status Branch Result
8.6 #496

This backport PR will be merged automatically after passing CI.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants