Skip to content

Fix global clearing of exclusion-only unique generators - #3334

Open
sergioperezcheco wants to merge 1 commit into
faker-ruby:mainfrom
sergioperezcheco:fix/clear-excluded-unique-values
Open

sergioperezcheco wants to merge 1 commit into
faker-ruby:mainfrom
sergioperezcheco:fix/clear-excluded-unique-values

Conversation

@sergioperezcheco

Copy link
Copy Markdown

Motivation / Background

Faker::UniqueGenerator.clear does not clear exclusions for a generator that has not generated a value since the last global clear. For example, excluding the only available value, calling global clear, and then generating it still raises RetryLimitExceeded.

Global clear walks the thread-local marked_unique set. Generation registers its wrapper in that set, but exclude only updates the results cache. Register the wrapper when exclusions are added too, using the same existing registration path. This also fixes exclusion-only use after a previous global clear without changing thread isolation or exclusion semantics.

Additional information

Added regression tests for exclusions before first generation, exclusions after a previous global clear, and clearing from another thread. Independently checked both lifecycle cases through Faker::Base.unique; the original implementation raises and the fix returns the excluded value after clearing.

On Ruby 3.4.11/macOS, the focused tests, full bundle exec rake test and RuboCop run, and FAKER_LAZY_LOAD=1 bundle exec rake test pass. Built and installed the gem into an isolated directory and checked the public API there too. The other Ruby/OS CI combinations have not been run locally.

AI assistance was used for investigation, implementation, and tests; the changes were independently reviewed and exercised by the coordinating agent.

Checklist

  • This Pull Request is related to one change.
  • Commit message describes what changed and why.
  • Tests are added for the bug fix.
  • Tests and Rubocop are passing before submission.

Register wrappers when exclude populates their thread-local results, so global clear also visits generators that have not generated a value since its last call. Cover both lifecycle cases and thread isolation.

Assisted-by: OpenAI
Signed-off-by: sergioperezcheco <checo520@outlook.com>
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.

1 participant