Skip to content

Commit

Permalink
Merge pull request #3867 from SFDO-Tooling/select_rows/default_record…
Browse files Browse the repository at this point in the history
…_selection_bug

Remove default declaration for select rows query
  • Loading branch information
jkasturi-sf authored Jan 9, 2025
2 parents ed82f07 + 409f4ee commit ee72965
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 70 deletions.
11 changes: 0 additions & 11 deletions cumulusci/tasks/bulkdata/select_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from pydantic import Field, root_validator, validator

from cumulusci.core.enums import StrEnum
from cumulusci.tasks.bulkdata.extract_dataset_utils.hardcoded_default_declarations import (
DEFAULT_DECLARATIONS,
)
from cumulusci.tasks.bulkdata.utils import CaseInsensitiveDict
from cumulusci.utils import get_cci_upgrade_command
from cumulusci.utils.yaml.model_parser import CCIDictModel
Expand Down Expand Up @@ -188,10 +185,6 @@ def standard_generate_query(
filter_clause=user_filter, limit_clause=limit, offset_clause=offset
)
else:
# Get the WHERE clause from DEFAULT_DECLARATIONS if available
declaration = DEFAULT_DECLARATIONS.get(sobject)
if declaration:
query += f" WHERE {declaration.where}"
query += f" LIMIT {limit}" if limit else ""
query += f" OFFSET {offset}" if offset else ""
return query, ["Id"]
Expand Down Expand Up @@ -281,10 +274,6 @@ def similarity_generate_query(
filter_clause=user_filter, limit_clause=limit, offset_clause=offset
)
else:
# Get the WHERE clause from DEFAULT_DECLARATIONS if available
declaration = DEFAULT_DECLARATIONS.get(sobject)
if declaration:
query += f" WHERE {declaration.where}"
query += f" LIMIT {limit}" if limit else ""
query += f" OFFSET {offset}" if offset else ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interactions:

- request:
method: GET
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id,%20Name,%20Description,%20Phone,%20AccountNumber%20FROM%20Account%20WHERE%20Name%20!=%20'Sample%20Account%20for%20Entitlements'
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id,%20Name,%20Description,%20Phone,%20AccountNumber%20FROM%20Account
body: null
headers: *id004
response:
Expand Down Expand Up @@ -125,7 +125,7 @@ interactions:

- request:
method: GET
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id%20FROM%20Account%20WHERE%20Name%20!=%20'Sample%20Account%20for%20Entitlements'%20LIMIT%205
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id%20FROM%20Account%20LIMIT%205
body: null
headers: *id004
response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interactions:

- request:
method: GET
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id,%20Name,%20Description,%20Phone,%20AccountNumber%20FROM%20Account%20WHERE%20Name%20!=%20'Sample%20Account%20for%20Entitlements'
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id,%20Name,%20Description,%20Phone,%20AccountNumber%20FROM%20Account
body: null
headers: *id004
response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interactions:

- request:
method: GET
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id,%20Name,%20Description,%20Phone,%20AccountNumber%20FROM%20Account%20WHERE%20Name%20!=%20'Sample%20Account%20for%20Entitlements'
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id,%20Name,%20Description,%20Phone,%20AccountNumber%20FROM%20Account
body: null
headers: *id004
response:
Expand Down Expand Up @@ -125,7 +125,7 @@ interactions:

- request:
method: GET
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id%20FROM%20Account%20WHERE%20Name%20!=%20'Sample%20Account%20for%20Entitlements'%20LIMIT%205
uri: https://orgname.my.salesforce.com/services/data/v62.0/query/?q=SELECT%20Id%20FROM%20Account%20LIMIT%205
body: null
headers: *id004
response:
Expand Down
57 changes: 3 additions & 54 deletions cumulusci/tasks/bulkdata/tests/test_select_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,7 @@
PANDAS_AVAILABLE = False


# Test Cases for standard_generate_query
def test_standard_generate_query_with_default_record_declaration():
select_operator = SelectOperationExecutor(SelectStrategy.STANDARD)
sobject = "Account" # Assuming Account has a declaration in DEFAULT_DECLARATIONS
limit = 5
offset = 2
query, fields = select_operator.select_generate_query(
sobject=sobject, fields=[], user_filter="", limit=limit, offset=offset
)

assert "WHERE" in query # Ensure WHERE clause is included
assert f"LIMIT {limit}" in query
assert f"OFFSET {offset}" in query
assert fields == ["Id"]


def test_standard_generate_query_without_default_record_declaration():
def test_standard_generate_query_without_filter():
select_operator = SelectOperationExecutor(SelectStrategy.STANDARD)
sobject = "Contact" # Assuming no declaration for this object
limit = 3
Expand All @@ -49,7 +33,6 @@ def test_standard_generate_query_without_default_record_declaration():
sobject=sobject, fields=[], user_filter="", limit=limit, offset=offset
)

assert "WHERE" not in query # No WHERE clause should be present
assert f"LIMIT {limit}" in query
assert "OFFSET" not in query
assert fields == ["Id"]
Expand All @@ -72,23 +55,7 @@ def test_standard_generate_query_with_user_filter():
assert fields == ["Id"]


# Test Cases for random generate query
def test_random_generate_query_with_default_record_declaration():
select_operator = SelectOperationExecutor(SelectStrategy.RANDOM)
sobject = "Account" # Assuming Account has a declaration in DEFAULT_DECLARATIONS
limit = 5
offset = 2
query, fields = select_operator.select_generate_query(
sobject=sobject, fields=[], user_filter="", limit=limit, offset=offset
)

assert "WHERE" in query # Ensure WHERE clause is included
assert f"LIMIT {limit}" in query
assert f"OFFSET {offset}" in query
assert fields == ["Id"]


def test_random_generate_query_without_default_record_declaration():
def test_random_generate_query():
select_operator = SelectOperationExecutor(SelectStrategy.RANDOM)
sobject = "Contact" # Assuming no declaration for this object
limit = 3
Expand All @@ -97,7 +64,6 @@ def test_random_generate_query_without_default_record_declaration():
sobject=sobject, fields=[], user_filter="", limit=limit, offset=offset
)

assert "WHERE" not in query # No WHERE clause should be present
assert f"LIMIT {limit}" in query
assert "OFFSET" not in query
assert fields == ["Id"]
Expand Down Expand Up @@ -209,23 +175,7 @@ def test_random_post_process_with_no_records():
assert error_message == f"No records found for {sobject} in the target org."


# Test Cases for Similarity Generate Query
def test_similarity_generate_query_with_default_record_declaration():
select_operator = SelectOperationExecutor(SelectStrategy.SIMILARITY)
sobject = "Account" # Assuming Account has a declaration in DEFAULT_DECLARATIONS
limit = 5
offset = 2
query, fields = select_operator.select_generate_query(
sobject, ["Name"], [], limit, offset
)

assert "WHERE" in query # Ensure WHERE clause is included
assert fields == ["Id", "Name"]
assert f"LIMIT {limit}" in query
assert f"OFFSET {offset}" in query


def test_similarity_generate_query_without_default_record_declaration():
def test_similarity_generate_query_no_nesting():
select_operator = SelectOperationExecutor(SelectStrategy.SIMILARITY)
sobject = "Contact" # Assuming no declaration for this object
limit = 3
Expand All @@ -234,7 +184,6 @@ def test_similarity_generate_query_without_default_record_declaration():
sobject, ["Name"], [], limit, offset
)

assert "WHERE" not in query # No WHERE clause should be present
assert fields == ["Id", "Name"]
assert f"LIMIT {limit}" in query
assert "OFFSET" not in query
Expand Down

0 comments on commit ee72965

Please sign in to comment.