Skip to content

Commit

Permalink
Merge pull request #3713 from SFDO-Tooling/bug/recordtype_tablename
Browse files Browse the repository at this point in the history
Incorrect generation of record type mapping table name in a namespaced org context
  • Loading branch information
vsbharath authored Dec 19, 2023
2 parents 359425d + ae32efa commit 8cc6f49
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cumulusci/tasks/bulkdata/query_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,28 @@ def filters_to_add(self):

@cached_property
def outerjoins_to_add(self):

if "RecordTypeId" in self.mapping.fields:
try:
rt_source_table = self.metadata.tables[
self.mapping.get_source_record_type_table()
]

except KeyError as e:
raise BulkDataException(
"A record type mapping table was not found in your dataset. "
f"Was it generated by extract_data? {e}",
) from e
# For generate_and_load_from_yaml, In case of namespace_inject true, mapping table name doesn't have namespace added
# We are checking for table_rt_mapping table
try:
rt_source_table = self.metadata.tables[
f"{self.mapping.table}_rt_mapping"
]

except KeyError as f:

raise BulkDataException(
"A record type mapping table was not found in your dataset. "
f"Was it generated by extract_data? {e}",
) from f

rt_dest_table = self.metadata.tables[
self.mapping.get_destination_record_type_table()
]
Expand Down
19 changes: 19 additions & 0 deletions cumulusci/tasks/bulkdata/tests/recordtypes_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BEGIN TRANSACTION;
CREATE TABLE Beta_rt_mapping (
record_type_id VARCHAR(18) NOT NULL,
developer_name VARCHAR(255),
PRIMARY KEY (record_type_id)
);
INSERT INTO "Beta_rt_mapping" VALUES('012H40000003jCoIAI','recordtype2');
INSERT INTO "Beta_rt_mapping" VALUES('012H40000003jCZIAY','recordtype1');
CREATE TABLE Beta (
id INTEGER NOT NULL,
"Name" VARCHAR(255),
"RecordType" VARCHAR(255),
PRIMARY KEY (id)
);

INSERT INTO "Beta" VALUES(15,'gamma12','012H40000003jCoIAI');
INSERT INTO "Beta" VALUES(16,'gamma','012H40000003jCZIAY');
INSERT INTO "Beta" VALUES(17,'gamma123','012H40000003jCZIAY');
COMMIT;
6 changes: 6 additions & 0 deletions cumulusci/tasks/bulkdata/tests/recordtypes_2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Insert Account:
sf_object: Account
table: Beta
fields:
Name: Name
RecordTypeId: RecordType
12 changes: 12 additions & 0 deletions cumulusci/tasks/bulkdata/tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,18 @@ def test_query_db__record_type_mapping(self):
""",
)

def test_query_db__record_type_mapping_table_from_tablename(self):
_validate_query_for_mapping_step(
sql_path="cumulusci/tasks/bulkdata/tests/recordtypes_2.sql",
mapping="cumulusci/tasks/bulkdata/tests/recordtypes_2.yml",
mapping_step_name="Insert Account",
expected="""SELECT "Beta".id AS "Beta_id", "Beta"."Name" AS "Beta_Name", "Account_rt_target_mapping".record_type_id AS "Account_rt_target_mapping_record_type_id"
FROM "Beta"
LEFT OUTER JOIN "Beta_rt_mapping" ON "Beta_rt_mapping".record_type_id = "Beta"."RecordType"
LEFT OUTER JOIN "Account_rt_target_mapping" ON "Account_rt_target_mapping".developer_name = "Beta_rt_mapping".developer_name
""",
)

@mock.patch("cumulusci.tasks.bulkdata.load.automap_base")
@responses.activate
def test_init_db__record_type_mapping(self, base):
Expand Down

0 comments on commit 8cc6f49

Please sign in to comment.