django-heroku-connect icon indicating copy to clipboard operation
django-heroku-connect copied to clipboard

Import mapping with "External-Id Relationship Fields"

Open amureki opened this issue 4 years ago • 0 comments

Description

Imagine you have the structure in your code/Salesforce like:

# salesforce/models.py
class SalesforceRelatedObject(hc_models.HerokuConnectModel):
    sf_object_name = 'RelatedObject__c'
    backend_uuid = hc_models.ExternalID(sf_field_name='BackendUUID__c',)


class MySalesforceObject(hc_models.HerokuConnectModel):
    related_object_id = hc_models.ID(
            sf_field_name='RelatedObject__c', unique=False, db_index=True
    )
    related_object = hc_models.Lookup(
        'salesforce.SalesforceRelatedObject',
        sf_field_name='RelatedObject__r__BackendUUID__c',
        blank=True,
        on_delete=models.SET_NULL,
        to_field='backend_uuid',
    )

In this case, import mappings command will produce mapping that contains both fields, but it would not generate an index part of the mapping for RelatedObject__c. This is silently breaking the whole mapping and RelatedObject__r__BackendUUID__c won't be added.

To Do

  1. We need to add a validation to prevent this kind of failure. This could be done somewhere around heroku_connect.db.models.base.HerokuConnectModel.get_heroku_connect_field_mapping
  2. A ticket to Heroku asking why this silently breaks would be also good.

amureki avatar Oct 15 '19 13:10 amureki