bullet icon indicating copy to clipboard operation
bullet copied to clipboard

Factory bot created resources - AVOID eager loading detected

Open tomca32 opened this issue 6 years ago • 11 comments

This started happening after upgrade to 5.8.1 from 5.7.5 We use Factory bot to create resources for testing and when creating a record with association Bullet complains about unnecessary eager loading. Here's an example:

  @grade = create :grade, grade_descriptor: @grade_descriptor1 # factory bot create
  @grade.update_grade_descriptor @grade_descriptor2
  expect(@grade.grade_descriptor).to eq @grade_descriptor2
AVOID eager loading detected
  Grade => [:grade_descriptor]
  Remove from your finder: :includes => [:grade_descriptor]

I guess that it doesn't like the fact that the first grade_descriptor was loaded and didn't even get used, which makes sense; however, it would be great if it could somehow ignore resources created via factories.

tomca32 avatar Nov 01 '18 15:11 tomca32

We are having the same issue.

sandipsubedi avatar Nov 14 '18 00:11 sandipsubedi

Same here. No solution in sight yet?

ArneZsng avatar Dec 06 '18 13:12 ArneZsng

same here

tsolar avatar Dec 06 '18 14:12 tsolar

I encounter the same problem. Any hints highly appreciated.

jann avatar Dec 06 '18 14:12 jann

My observation is that it works in the combination of bullet (5.7.5) and factory_bot (4.11.1), but neither with bullet (5.9.0) nor bullet (5.7.6).

ArneZsng avatar Dec 06 '18 15:12 ArneZsng

I am still having problems with 5.7.5.

I have a factory like this

FactoryBot.define do
  factory :ticket do
    ...
    trip_segment do
      trip = create(:trip)
      trip.trip_segments.first
    end
    ...
  end
end

And I get this

USE eager loading detected
         Ticket => [:trip]
         Add to your finder: :includes => [:trip]

What is wrong?

tsolar avatar Dec 07 '18 13:12 tsolar

I checked if it works with bullet (5.9.0), and it does. The spec using that factory passes, but having the same AVOID eager loading problem with others.

tsolar avatar Dec 07 '18 14:12 tsolar

It looks like for my problem the PR that introduced it was https://github.com/flyerhzm/bullet/pull/418

can replicate it using

class Foo < ActiveRecord::Base
  belongs_to :bar
end

class Bar < ActiveRecord::Base
end

Foo.create; Bar.create

Bullet.profile do
  foo = Foo.first
  foo.bar = Bar.first
end
AVOID eager loading detected
  Foo => [:bar]
  Remove from your finder: :includes => [:bar]

I have quite a limited understanding of how bullet works but Is this the intended behaviour @ccutrer ?

spheric avatar Dec 28 '18 01:12 spheric

@flyerhzm Any update on this issue?

spheric avatar Apr 12 '19 00:04 spheric

Anything new we can do on this?

dandunckelman avatar Sep 23 '21 15:09 dandunckelman

Anything new we can do on this?

Can we use the safelist for factories?

dandunckelman avatar Sep 23 '21 15:09 dandunckelman