Skip to content

Conversation

@rodrigobnogueira
Copy link

Summary

This PR enables factory.fuzzy attributes to correctly evaluate nested declarations (e.g. LazyAttribute, SelfAttribute, LazyFunction) when passed as arguments.

Fixes

Changes

  • Core Logic: Added a _resolve helper mechanism to BaseFuzzyAttribute to recursively evaluate declarations passed as parameters.
  • Fuzzy Classes Updated:
    • FuzzyChoice: Now resolves choices generator.
    • FuzzyInteger, FuzzyDecimal, FuzzyFloat: Now resolve low and high bounds.
    • FuzzyDate: Now resolves start_date and end_date.
    • FuzzyDateTime: Now resolves start_dt and end_dt.
  • Backward Compatibility: FuzzyDate and FuzzyDateTime logic was adjusted to defer validation until fuzz() time if (and only if) declarations are used, ensuring existing usage (e.g. end_date=None) remains unchanged.

Verification

  • New Tests: Added comprehensive test cases for:

    • FuzzyChoice with LazyAttribute, SelfAttribute, etc.
    • FuzzyInteger and FuzzyFloat with dynamic bounds.
    • FuzzyDate and FuzzyDateTime with dynamic, instance-dependent bounds.
    • Specific Case: Verified FuzzyDate(start_date=SelfAttribute('sys_created_at')) works as expected.
  • Suite: Ran full test suite; all 457 tests passed.

  • Linting: Verified compliance with project standards (PEP8/flake8, isort).

  • Docs: Marked the feature as "Accomplished" in the ideas list.

Recursive resolution of declarations in BaseFuzzyAttribute.
Fixes FactoryBoy#1050

- BaseFuzzyAttribute now resolves nested declarations (e.g. LazyAttribute)
- Updated FuzzyChoice, FuzzyInteger, FuzzyFloat, FuzzyDate, FuzzyDateTime
- Added tests for nested declarations in all fuzzy types
- Updated documentation
@rodrigobnogueira rodrigobnogueira force-pushed the feature/nested-fuzzy-declarations branch from 73464eb to 31e43ae Compare January 9, 2026 18:38
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.

FuzzyChoice does not accept SelfAttribute

1 participant