Skip to content

fix: prevent mutation of global PROVIDERS list in Factory.create#2331

Closed
GitMike01 wants to merge 1 commit intojoke2k:masterfrom
GitMike01:fix/issue-2311
Closed

fix: prevent mutation of global PROVIDERS list in Factory.create#2331
GitMike01 wants to merge 1 commit intojoke2k:masterfrom
GitMike01:fix/issue-2311

Conversation

@GitMike01
Copy link

What does this change

Changed the way providers and includes are combined in Factory.create to ensure the original list is not modified

What was wrong

The code was using the in-place addition operator (+=) on the providers list. When providers defaulted to the global PROVIDERS constant, this operator mutated the global list itself. This caused side effects where subsequent Faker instances would unexpectedly contain providers from previous instances

How this fixes it

Replaced the in-place operator += with the concatenation operator +. This creates a new list for the local scope of the function, leaving the global PROVIDERS constant intact and preventing unintended side effects.

Fixes #2311

AI Assistance Disclosure (REQUIRED)

  • No AI tools were used in preparing this PR.
  • If AI tools were used, I have disclosed which ones, and fully reviewed and verified their output.

Checklist

  • I have read the documentation about CONTRIBUTING
  • I have read the documentation about Coding style
  • I have run make lint

providers = providers or PROVIDERS

providers += includes
providers = providers + includes
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the AI might be hallucinating here. I don't see how the change would prevent mutation. If it does, please add a comment explaining.

@fcurella
Copy link
Collaborator

Duplicate of #2313

@fcurella fcurella marked this as a duplicate of #2313 Mar 12, 2026
@fcurella fcurella closed this Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default providers accidentally changed

2 participants