Describe the bug
Faker::Config.lazy_loading does not appear to work as described in the CHANGELOG.
Faker 3.8.0 introduces a lazy loading option and documents two ways to enable it:
- Set
Faker::Config.lazy_loading = true
- Set the environment variable
FAKER_LAZY_LOAD=1
However, Faker::Config.lazy_loading = true has no effect in practice.
This is because require "faker" triggers eager loading immediately unless the environment variable is already set. Changing the config value afterward does not retroactively switch to lazy loading.
To Reproduce
1. Default behavior (eager load)
irb(main):001> require "faker";
irb(main):002> puts Faker::VERSION;
# => 3.8.0
irb(main):003> p Faker.constants;
# => [:Types, :Compass, :IdNumber, :UniqueGenerator, :Adjective, :Alphanumeric, :Computer, :Construction, :Source, :Config, :Cosmere, :Ancient, :String, :App, :Appliance, :Artist, :Avatar, :Lorem, :Bank, :Blockchain, :Books, :Creature, :Fantasy, :Games, :Internet, :Crypto, :Markdown, :CryptoCoin, :ProgrammingLanguage, :Quote, :Barcode, :Currency, :Name, :IndustrySegments, :Invoice, :Relationship, :Restaurant, :Company, :Job, :Science, :Beer, :DcComics, :VERSION, :Demographic, :Json, :Blood, :Kpop, :Book, :Dessert, :Boolean, :Time, :Business, :Device, :SlackEmoji, :Camera, :DrivingLicence, :JapaneseMedia, :Locations, :Movies, :Music, :X, :Cannabis, :SouthAfrica, :ChileRut, :LoremFlickr, :InvalidStatePassed, :Marketing, :Space, :Quotes, :Religion, :Sports, :Drone, :Default, :TvShows, :ChuckNorris, :File, :Base, :Code, :Measurement, :Military, :Travel, :Date, :Number, :Sport, :Mountain, :Movie, :Stripe, :Educator, :Nation, :Coffee, :ElectricalComponents, :NationalHealthService, :Subscription, :Emotion, :NatoPhoneticAlphabet, :Coin, :Esport, :Superhero, :Tea, :Base58, :Team, :Theater, :Char, :Finance, :Color, :Deprecator, :Omniauth, :Commerce, :PhoneNumber, :Food, :University, :Placeholdit, :Vehicle, :FunnyName, :Game, :GreekPhilosophers, :Hacker, :Hipster, :Hobby, :Gender, :House, :HTML, :Address, :Verb, :VulnerabilityIdentifier, :WorldCup]
2. Lazy load (works only with environment variable)
$ FAKER_LAZY_LOAD=1 irb
irb(main):001> require "faker";
irb(main):002> puts Faker::VERSION;
# => 3.8.0
irb(main):003> p Faker.constants;
# => [:Deprecator, :Base, :Config, :VERSION, :Base58, :Char, :UniqueGenerator]
3. Setting Faker::Config.lazy_loading = true after require has no effect
$ irb
irb(main):001> require "faker";
irb(main):002> puts Faker::VERSION;
# => 3.8.0
irb(main):003> Faker::Config.lazy_loading = true;
irb(main):004> p Faker.constants;
# => [:Types, :Compass, :IdNumber, :UniqueGenerator, :Adjective, :Alphanumeric, :Computer, :Construction, :Source, :Config, :Cosmere, :Ancient, :String, :App, :Appliance, :Artist, :Avatar, :Lorem, :Bank, :Blockchain, :Books, :Creature, :Fantasy, :Games, :Internet, :Crypto, :Markdown, :CryptoCoin, :ProgrammingLanguage, :Quote, :Barcode, :Currency, :Name, :IndustrySegments, :Invoice, :Relationship, :Restaurant, :Company, :Job, :Science, :Beer, :DcComics, :VERSION, :Demographic, :Json, :Blood, :Kpop, :Book, :Dessert, :Boolean, :Time, :Business, :Device, :SlackEmoji, :Camera, :DrivingLicence, :JapaneseMedia, :Locations, :Movies, :Music, :X, :Cannabis, :SouthAfrica, :ChileRut, :LoremFlickr, :InvalidStatePassed, :Marketing, :Space, :Quotes, :Religion, :Sports, :Drone, :Default, :TvShows, :ChuckNorris, :File, :Base, :Code, :Measurement, :Military, :Travel, :Date, :Number, :Sport, :Mountain, :Movie, :Stripe, :Educator, :Nation, :Coffee, :ElectricalComponents, :NationalHealthService, :Subscription, :Emotion, :NatoPhoneticAlphabet, :Coin, :Esport, :Superhero, :Tea, :Base58, :Team, :Theater, :Char, :Finance, :Color, :Deprecator, :Omniauth, :Commerce, :PhoneNumber, :Food, :University, :Placeholdit, :Vehicle, :FunnyName, :Game, :GreekPhilosophers, :Hacker, :Hipster, :Hobby, :Gender, :House, :HTML, :Address, :Verb, :VulnerabilityIdentifier, :WorldCup]
Expected behavior
I expected that setting Faker::Config.lazy_loading = true after requiring the gem would enable lazy loading.
If this setting must be applied before requiring the gem (and cannot work afterward), the documentation should clearly state this.
Additional context
The root cause appears to be that eager loading happens during require "faker", based on the value of lazy_loading? at that moment. Changing the config later does not undo the eager load.
Describe the bug
Faker::Config.lazy_loadingdoes not appear to work as described in the CHANGELOG.Faker 3.8.0 introduces a lazy loading option and documents two ways to enable it:
Faker::Config.lazy_loading = trueFAKER_LAZY_LOAD=1However,
Faker::Config.lazy_loading = truehas no effect in practice.This is because
require "faker"triggers eager loading immediately unless the environment variable is already set. Changing the config value afterward does not retroactively switch to lazy loading.To Reproduce
1. Default behavior (eager load)
2. Lazy load (works only with environment variable)
3. Setting
Faker::Config.lazy_loading = trueafter require has no effectExpected behavior
I expected that setting
Faker::Config.lazy_loading = trueafter requiring the gem would enable lazy loading.If this setting must be applied before requiring the gem (and cannot work afterward), the documentation should clearly state this.
Additional context
The root cause appears to be that eager loading happens during
require "faker", based on the value oflazy_loading?at that moment. Changing the config later does not undo the eager load.