Fix mutation of data_types causing order-dependent behavior#5037
Fix mutation of data_types causing order-dependent behavior#5037Adir-html wants to merge 1 commit intoansys:mainfrom
Conversation
|
The following people have not signed the Contributors License Agreement (CLA): Read the CLA in the link above and sign it by clicking the link below: You will receive a confirmation as soon as your signature is captured. |
Up to standards ✅🟢 Issues
|
There was a problem hiding this comment.
Pull request overview
Fixes order-dependent behavior in FileFieldData._get_surface_data() by eliminating in-place mutation of the data_types iterable during normalization to SurfaceDataType.
Changes:
- Replace in-loop
remove/appendmutation ofdata_typeswith a new list constructed via comprehension to preserve input order. - Ensure
data_typesentries are normalized toSurfaceDataTypebefore downstream membership checks.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| d_type if isinstance(d_type, SurfaceDataType) | ||
| else SurfaceDataType(d_type) | ||
| for d_type in data_types | ||
| ] |
There was a problem hiding this comment.
The new list comprehension is indented inconsistently with the surrounding method body and will be reformatted by Black (and may fail formatting checks in CI/pre-commit). Please re-indent this block to Black-style indentation so the comprehension lines align under the opening bracket within the method scope.
| d_type if isinstance(d_type, SurfaceDataType) | |
| else SurfaceDataType(d_type) | |
| for d_type in data_types | |
| ] | |
| d_type if isinstance(d_type, SurfaceDataType) | |
| else SurfaceDataType(d_type) | |
| for d_type in data_types | |
| ] |
| data_types = [ | ||
| d_type if isinstance(d_type, SurfaceDataType) | ||
| else SurfaceDataType(d_type) | ||
| for d_type in data_types | ||
| ] |
There was a problem hiding this comment.
Great. As well as not mutating the container while iterating, it also uses a positive type check.
There was a problem hiding this comment.
You don't really need the type check here as suggested in the original issue as Enum(Enum.member) -> Enum.member
|
@Adir-html, could you please fix the code styling issue in this PR. There is a co-pilot suggestion as well, please feel free to commit it. |
|
@copilot apply changes based on the comments in this thread |
Fix mutation of data_types causing order-dependent behavior
The current implementation mutates the
data_typeslist while iterating over it, which can lead to order-dependent behavior and inconsistent return types.This PR replaces the mutation logic with a list comprehension that preserves order and avoids in-place modification:
This ensures consistent behavior regardless of input ordering.
Tested using the reproduction steps from the issue.