Skip to content

Commit d3445da

Browse files
author
bosd
committed
[FIX] attribute_set: apply restrictive approach to both create and write operations
- Implement whitelist approach for both native attribute creation and updates - Only allow safe attribute-specific fields for native attributes in both operations - Prevent modification of underlying ir.model.fields records during native attribute operations - Ensure consistent behavior between creation and update operations - Completely eliminate possibility of base field modification errors
1 parent 22164e9 commit d3445da

1 file changed

Lines changed: 23 additions & 27 deletions

File tree

attribute_set/models/attribute_attribute.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -510,41 +510,37 @@ def write(self, vals):
510510
# Check if any records in this write operation are native attributes
511511
has_native_attrs = any(att.nature == "native" for att in self)
512512

513-
# If we have native attributes, filter out dangerous keys that modify
514-
# ir.model.fields characteristics to prevent base field modification errors
513+
# If we have native attributes, use whitelist to allow only safe fields
515514
processed_vals = vals.copy()
516515
if has_native_attrs:
517-
# These fields are known to trigger the base field modification error
518-
dangerous_fields = {
516+
# Only allow attribute-specific fields that don't modify underlying record
517+
allowed_fields = {
519518
"name",
520519
"field_description",
521-
"ttype",
522-
"relation",
520+
"attribute_type",
521+
"attribute_group_id",
522+
"attribute_set_ids",
523+
"sequence",
524+
"required_on_views",
525+
"widget",
526+
"help",
523527
"size",
524-
"required",
525-
"readonly",
526528
"translate",
527-
"selection",
529+
"relation_model_id",
528530
"domain",
529-
"compute",
530-
"store",
531-
"copy",
532-
"index",
533-
"manual",
534-
"depends",
535-
"related",
536-
"company_dependent",
537-
"prefetch",
538-
"group_operator",
539-
"digits",
540-
"on_delete",
541-
"help",
542-
"field_id",
543-
"model_id",
531+
"option_ids",
532+
"serialized",
533+
"serialized_name",
534+
"create_uid",
535+
"write_uid",
536+
"create_date",
537+
"write_date",
538+
"id",
539+
}
540+
# Keep only allowed fields, remove others that could modify base fields
541+
processed_vals = {
542+
k: v for k, v in processed_vals.items() if k in allowed_fields
544543
}
545-
# Remove these keys to prevent modification of base field characteristics
546-
for key in dangerous_fields.intersection(set(processed_vals.keys())):
547-
processed_vals.pop(key, None)
548544

549545
# Perform the write operation with filtered values
550546
res = super().write(processed_vals)

0 commit comments

Comments
 (0)