Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Id Not Specified on Update Call #3761

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cumulusci/tasks/bulkdata/query_transformers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing as T
from functools import cached_property

from sqlalchemy import and_, func, text
from sqlalchemy import String, and_, func, text
from sqlalchemy.orm import Query, aliased

from cumulusci.core.exceptions import BulkDataException
Expand Down Expand Up @@ -75,7 +75,7 @@ def join_for_lookup(lookup):
return (
lookup.aliased_table,
lookup.aliased_table.columns.id
== str(lookup.table) + "-" + value_column,
== str(lookup.table) + "-" + func.cast(value_column, String),
)
else:
return (
Expand Down
6 changes: 4 additions & 2 deletions cumulusci/tasks/bulkdata/tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,20 +871,22 @@ def test_get_statics_record_type_not_matched(self):
assert "RecordType" in str(e.value)

def test_query_db__joins_self_lookups(self):
"""SQL file in Old Format"""
_validate_query_for_mapping_step(
sql_path=Path(__file__).parent / "test_query_db__joins_self_lookups.sql",
mapping=Path(__file__).parent / "test_query_db__joins_self_lookups.yml",
mapping_step_name="Update Accounts",
expected="""SELECT accounts.id AS accounts_id, accounts."Name" AS "accounts_Name", cumulusci_id_table_1.sf_id AS cumulusci_id_table_1_sf_id FROM accounts LEFT OUTER JOIN cumulusci_id_table AS cumulusci_id_table_1 ON cumulusci_id_table_1.id = ? || accounts.parent_id ORDER BY accounts.parent_id""",
expected="""SELECT accounts.id AS accounts_id, accounts."Name" AS "accounts_Name", cumulusci_id_table_1.sf_id AS cumulusci_id_table_1_sf_id FROM accounts LEFT OUTER JOIN cumulusci_id_table AS cumulusci_id_table_1 ON cumulusci_id_table_1.id = ? || cast(accounts.parent_id as varchar) ORDER BY accounts.parent_id""",
old_format=True,
)

def test_query_db__joins_polymorphic_lookups(self):
"""SQL File in New Format (Polymorphic)"""
_validate_query_for_mapping_step(
sql_path=Path(__file__).parent / "test_query_db_joins_lookups.sql",
mapping=Path(__file__).parent / "test_query_db_joins_lookups.yml",
mapping_step_name="Update Event",
expected="""SELECT events.id AS events_id, events."Subject" AS "events_Subject", cumulusci_id_table_1.sf_id AS cumulusci_id_table_1_sf_id FROM events LEFT OUTER JOIN cumulusci_id_table AS cumulusci_id_table_1 ON cumulusci_id_table_1.id = ? || events."WhoId" ORDER BY events."WhoId" """,
expected="""SELECT events.id AS events_id, events."Subject" AS "events_Subject", cumulusci_id_table_1.sf_id AS cumulusci_id_table_1_sf_id FROM events LEFT OUTER JOIN cumulusci_id_table AS cumulusci_id_table_1 ON cumulusci_id_table_1.id = ? || cast(events."WhoId" as varchar) ORDER BY events."WhoId" """,
)

@responses.activate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BEGIN TRANSACTION;
CREATE TABLE "accounts" (
id VARCHAR(255) NOT NULL,
id INTEGER NOT NULL,
"Name" VARCHAR(255),
"parent_id" VARCHAR(255),
PRIMARY KEY (id)
Expand Down
Loading