Skip to content

Fix TruncateTransform.satisfies_order_of for different widths - #4275

Open
linzch3 wants to merge 2 commits into
apache:mainfrom
linzch3:fix/truncate-satisfies-order-of
Open

linzch3 wants to merge 2 commits into
apache:mainfrom
linzch3:fix/truncate-satisfies-order-of

Conversation

@linzch3

@linzch3 linzch3 commented Nov 3, 2026 •

Copy link
Copy Markdown

Closes #3680

Rationale for this change

TruncateTransform.satisfies_order_of reads self.source_type, but _source_type is never set on TruncateTransform, so comparing two truncate transforms with different widths raises:

AttributeError: 'TruncateTransform' object has no attribute '_source_type'

Following review feedback, this now matches the Java Truncate.satisfiesOrderOf: a truncate transform satisfies the order of another truncate transform when its width is greater than or equal to the other's. It no longer reads the missing source_type.

I left the source_type property in place to avoid an API change.

This picks up the same bug as #3681, #3682 and #3854, which the stale bot closed.

Are these changes tested?

Yes. test_truncate_satisfies_order_of_different_widths in tests/test_transforms.py covers equal widths, both directions of different widths, and other transform types. tests/test_transforms.py passes locally, and ruff check and ruff format pass.

Are there any user-facing changes?

TruncateTransform(a).satisfies_order_of(TruncateTransform(b)) now returns a >= b instead of raising AttributeError when a != b.


This change was prepared with an AI coding assistant, and the tests were run locally. The commits have a Generated-by: trailer, following the ASF generative tooling guidance.

satisfies_order_of read source_type, which is never set on TruncateTransform,
so comparing two truncate transforms with different widths raised
AttributeError. The source type is not known on the unbound transform, and a
wider truncation only preserves the order of a narrower one for strings, so
only equal transforms are reported as satisfying the order.

Closes apache#3680

Generated-by: Grok Bot (AI coding assistant)

@rambleraptor rambleraptor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Java implementation specifically checks widths. I'm not sure if this is the approach we want to take.

A truncate transform satisfies the order of another truncate transform when
its width is greater than or equal to the other's, as in the Java Truncate
implementation. This no longer reads the missing source_type attribute.

Generated-by: Grok Bot (AI coding assistant)

This branch has not been deployed

No deployments
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.

TruncateTransform.satisfies_order_of raises AttributeError for different widths

2 participants