Skip to content

external_id_mapping fails for non compound unique indexes with underscores #2336

@lsmith77

Description

@lsmith77

The RestApiHandler's external_id_mapping configuration incorrectly parses single-field unique indexes that contain underscores in their field names, treating them as compound IDs instead.

Current Behavior:

When using external_id_mapping with a single field name containing underscores:

external_id_mapping: {
  MyModel: 'external_unique_id'
}

Error:

The handler splits 'external_unique_id' by underscores into ['external', 'unique', 'id'] and attempts to find fields with those names, failing when they don't exist as separate fields.

Expected Behavior
external_id_mapping should support:

  • Single-field unique indexes: { MyModel: 'external_unique_id' } where external_unique_id is one field
  • Compound unique indexes: { MyModel: 'field1_field2' } where field1 and field2 are separate fields

Fixes

I see two possible fixes:

  1. Check if a field exists before splitting
  2. Optionally allow passing in an array of field names

For 1) it is a bit iffy, since this only really fixes the issue for non-compound columns. But since in theory the issue could also affect compound indexes, 2) would be cleaner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions