Skip to content

Conversation

@rodrigobnogueira
Copy link

Summary

Fixes #1119 - Transformer not used with trait and value override

When a field has both a base Transformer and a Trait that overrides it with another Transformer, user-provided overrides were bypassing the base transformer entirely when the trait was not active.

Root Cause

When a Trait wraps a field, it replaces the declaration with a Maybe that selects between the trait's value (yes_declaration) and the base value (no_declaration). However, Maybe didn't propagate the CAPTURE_OVERRIDES attribute from its branches, so user overrides would replace the entire Maybe declaration instead of being forwarded to the appropriate transformer.

Solution

Added CAPTURE_OVERRIDES propagation from no_declaration in Maybe.__init__. This ensures that when the trait is NOT active and there's a base Transformer, user overrides are properly forwarded to the base transformer.

self.CAPTURE_OVERRIDES = getattr(no_declaration, 'CAPTURE_OVERRIDES', False)

The fix specifically uses no_declaration (not both branches with or) to preserve the existing behavior where user overrides bypass the trait's transformer when the trait IS active.

Testing

  • 2 new regression tests added to tests/test_transformer.py
  • Full test suite passes (449 tests)
  • Tests cover both trait-inactive and trait-active scenarios

Checklist

  • Tests pass locally
  • New tests added for new functionality
  • Follows existing code style
  • Linting passes

…#1119)

When a field has both a base Transformer and a Trait that overrides it,
user-provided overrides were bypassing the base transformer when the
trait was not active.

Fixed by propagating CAPTURE_OVERRIDES from no_declaration in Maybe
class, ensuring overrides are forwarded to the base transformer.
@rodrigobnogueira rodrigobnogueira force-pushed the fix/transformer-trait-override-1119 branch from 30712f9 to ddc8091 Compare January 14, 2026 16:02
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.

Transformer not used with trait and value override

1 participant