Skip to content

Commit

Permalink
Merge pull request #270 from ForgeFlow/master-merge_records-add-optio…
Browse files Browse the repository at this point in the history
…n-preserve-fields

[IMP] merge_records: option to exclude all fields not in field_spec
  • Loading branch information
pedrobaeza authored Dec 22, 2021
2 parents 3d2e190 + e5e31d5 commit bd66762
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions openupgradelib/openupgrade_merge_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ def _adjust_merged_values_orm(env, model_name, record_ids, target_record_id,
:param: field_spec: Dictionary with field names as keys and forced
operation to perform as values. If a field is not present here, default
operation will be performed.
Note: If you pass 'openupgrade_other_fields': 'preserve' in the dict,
the fields that are not specified in the dict will not be adjusted.
Possible operations by field types:
Expand Down Expand Up @@ -460,6 +462,9 @@ def _adjust_merged_values_orm(env, model_name, record_ids, target_record_id,
vals = {}
o2m_changes = 0
for field in fields:
if field_spec.get('openupgrade_other_fields', '') == 'preserve' \
and field.name not in field_spec:
continue
if not field.store or field.compute or field.related:
continue # don't do anything on these cases
op = field_spec.get(field.name, False)
Expand Down Expand Up @@ -500,6 +505,8 @@ def _adjust_merged_values_sql(env, model_name, record_ids, target_record_id,
:param: field_spec: Dictionary with field names as keys and forced
operation to perform as values. If a field is not present here, default
operation will be performed.
Note: If you pass 'openupgrade_other_fields': 'preserve' in the dict,
the fields that are not specified in the dict will not be adjusted.
Possible operations by field types same as _adjust_merged_values_orm.
"""
Expand Down Expand Up @@ -527,6 +534,9 @@ def _adjust_merged_values_sql(env, model_name, record_ids, target_record_id,
new_vals = {}
vals = {}
for i, (column, column_type, field_type) in enumerate(dict_column_type):
if field_spec.get('openupgrade_other_fields', '') == 'preserve' \
and column not in field_spec:
continue
op = field_spec.get(column, False)
_list = list(lists[i])
field_vals = apply_operations_by_field_type(
Expand Down

0 comments on commit bd66762

Please sign in to comment.