Skip to content

Conversation

@rodrigobnogueira
Copy link

Summary

Add literal_keys Meta option to allow field names containing double underscores without triggering deep context parsing.

Fixes

Changes

  • Added literal_keys option to FactoryOptions
  • Updated DeclarationSet to respect literal keys
  • Improved error messages: When an InvalidDeclarationError is raised due to deep context parsing, the error now includes a helpful hint suggesting Meta.literal_keys=['field__name']
  • Added tests and documentation

Example

class ServiceFactory(factory.Factory):
    class Meta:
        model = Service
        literal_keys = ['service__name']
    
    service__name = "foo"

Verification

  • All 442 tests pass
  • Linting clean (make lint)
  • New tests added in tests/test_base.py:
    • test_literal_keys: verifies keys are preserved without splitting
    • test_literal_keys_inheritance: verifies option inheritance
    • test_literal_keys_missing_raises_error: verifies helpful error hint

Add literal_keys Meta option to allow field names containing double
underscores without triggering deep context parsing.

Closes FactoryBoy#1118
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.

Is there a way to disable "deep context" for a factory?

1 participant