fix(factory): avoid mutating module-level PROVIDERS list#2336
Closed
Dhi13man wants to merge 1 commit intojoke2k:masterfrom
Closed
fix(factory): avoid mutating module-level PROVIDERS list#2336Dhi13man wants to merge 1 commit intojoke2k:masterfrom
Dhi13man wants to merge 1 commit intojoke2k:masterfrom
Conversation
`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>
Collaborator
|
Duplicate of #2331 |
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. |
Collaborator
|
Duplicate of #2313 |
Collaborator
|
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. |
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Factory.create()usedproviders += includeswhich mutates the module-levelPROVIDERSlist in-place. When no customprovidersargument is passed, the local variable aliases the globalPROVIDERS, so+=permanently appendsincludesto it. Every subsequentFactory.create()call then inherits previously included providers.providers += includeswithproviders = providers + includes(line 50 infaker/factory.py), which creates a new list instead of mutating the original.test_includes_does_not_mutate_default_providersregression test that verifiesPROVIDERSlength is unchanged after callingFactory.create(includes=...).Closes #2311
Test plan
test_includes_does_not_mutate_default_providerspassestests/test_factory.pysuite passes (24 tests)