Skip to content

fix(factory): avoid mutating module-level PROVIDERS list#2336

Closed
Dhi13man wants to merge 1 commit intojoke2k:masterfrom
Dhi13man:fix/mutable-default-providers
Closed

fix(factory): avoid mutating module-level PROVIDERS list#2336
Dhi13man wants to merge 1 commit intojoke2k:masterfrom
Dhi13man:fix/mutable-default-providers

Conversation

@Dhi13man
Copy link

@Dhi13man Dhi13man commented Mar 12, 2026

Summary

  • Bug: Factory.create() used providers += includes which mutates the module-level PROVIDERS list in-place. When no custom providers argument is passed, the local variable aliases the global PROVIDERS, so += permanently appends includes to it. Every subsequent Factory.create() call then inherits previously included providers.
  • Fix: Replace providers += includes with providers = providers + includes (line 50 in faker/factory.py), which creates a new list instead of mutating the original.
  • Test: Added test_includes_does_not_mutate_default_providers regression test that verifies PROVIDERS length is unchanged after calling Factory.create(includes=...).

Closes #2311

Test plan

  • New regression test test_includes_does_not_mutate_default_providers passes
  • Full tests/test_factory.py suite passes (24 tests)
  • Linted with ruff — no issues

`Factory.create()` used `providers += includes` which mutates the
module-level `PROVIDERS` list when no custom providers are passed.
Subsequent calls then see the previously included providers, causing
unexpected provider accumulation.

Replace `+=` (in-place extend) with `= ... +` (new list) so the
default `PROVIDERS` is never modified.

Closes #2311

Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
@fcurella
Copy link
Collaborator

Duplicate of #2331

@fcurella fcurella marked this as a duplicate of #2331 Mar 12, 2026
@fcurella fcurella closed this Mar 12, 2026
@Dhi13man
Copy link
Author

I had leftover Claude Max and wanted to contribute to backlog clearing in open source projects before it reset, but I see that this could be a nuisance. My apologies.

@fcurella
Copy link
Collaborator

Duplicate of #2313

@fcurella fcurella marked this as a duplicate of #2313 Mar 12, 2026
@fcurella
Copy link
Collaborator

fcurella commented Mar 12, 2026

The test actually prove this is a bug, and that the change fixes it. I'm re-opening this PR and closing the other ones.

@fcurella
Copy link
Collaborator

Close #2313, #2331

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.

Default providers accidentally changed

2 participants