Skip to content

Fix: RecordFactory defaultValue prevents mapping execution #9060

@tobiu

Description

@tobiu

Neo.data.RecordFactory has a logic flaw in assignDefaultValues where defaultValue assignment takes precedence over mapping.

Current Logic:

if (Object.hasOwn(field, 'defaultValue')) {
    // ...
    if (data[fieldName] === undefined) {
        data[fieldName] = defaultValue; // Assigns default
    }
} else if (field.mapping) { // ELSE IF prevents mapping!
    // Mapping logic...
}

Problem:
If a field has both defaultValue and mapping (e.g. {name: 'location', mapping: 'lc', defaultValue: null}), and the raw data contains the mapped key (lc) but not the target key (location):

  1. data['location'] is undefined.
  2. It enters the first if.
  3. It assigns null to data['location'].
  4. It SKIPS the else if block, so the mapping from lc never happens.

Solution:
The mapping logic must run before the default value check, or they must be decoupled so that mapping can populate the field first, and then the default value fills in only if it remains undefined.

Metadata

Metadata

Assignees

Labels

aibugSomething isn't workingcoreCore framework functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions