SFDO-Tooling / CumulusCI

Python framework for building portable automation for Salesforce projects
http://cumulusci.readthedocs.io
BSD 3-Clause "New" or "Revised" License
353 stars 239 forks source link

Fix Id Not Specified on Update Call #3761

Closed aditya-balachander closed 4 months ago

aditya-balachander commented 4 months ago

W-15182566

These modifications address the error reported in Slack Thread

Error Reason: The old format of sql files use the id field to be of type INTEGER:

CREATE TABLE "accounts" (
    id INTEGER NOT NULL, 
    "Name" VARCHAR(255), 
    "parent_id" VARCHAR(255), 
    PRIMARY KEY (id)
);
INSERT INTO "accounts" VALUES(1,'Bluth','');
INSERT INTO "accounts" VALUES(2,'Funke-Bluth',1);

During handling of adding the outerjoins for lookups, when we specified the condition, we were concatenating a string with an integer:

def join_for_lookup(lookup):
            key_field = lookup.get_lookup_key_field(self.model)
            value_column = getattr(self.model, key_field)
            if self._old_format:
                return (
                    lookup.aliased_table,
                    lookup.aliased_table.columns.id
                    == str(lookup.table) + "-" + value_column,
                    # Here value_column can be an integer in old format
                )
            else:
                return (
                    lookup.aliased_table,
                    lookup.aliased_table.columns.id == value_column,
                )

This resulted in the query not returning anything during the update call of the record. Hence the error, Id not specified in an update call

Solution:

We have updated the condition to cast the id column to a string so that successful concatenation happens.

def join_for_lookup(lookup):
            key_field = lookup.get_lookup_key_field(self.model)
            value_column = getattr(self.model, key_field)
            if self._old_format:
                return (
                    lookup.aliased_table,
                    lookup.aliased_table.columns.id
                    == str(lookup.table) + "-" + func.cast(value_column, String),
                )
            else:
                return (
                    lookup.aliased_table,
                    lookup.aliased_table.columns.id == value_column,
                )