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

🐛 Source Salesforce: fix bug with pagination for BULK API #6209

Merged
merged 4 commits into from
Sep 21, 2021

Conversation

yevhenii-ldv
Copy link
Contributor

What

closes #6122.

How

Describe the solution

Recommended reading order

  1. x.java
  2. y.python

Pre-merge Checklist

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions
  • Connector version bumped like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

@github-actions github-actions bot added area/connectors Connector related issues area/documentation Improvements or additions to documentation labels Sep 17, 2021
@yevhenii-ldv
Copy link
Contributor Author

yevhenii-ldv commented Sep 17, 2021

/test connector=connectors/source-salesforce

🕑 connectors/source-salesforce https://github.com/airbytehq/airbyte/actions/runs/1245431701
✅ connectors/source-salesforce https://github.com/airbytehq/airbyte/actions/runs/1245431701
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                 Stmts   Miss  Cover
	 ------------------------------------------------------------------------
	 source_acceptance_test/__init__.py                       2      0   100%
	 source_acceptance_test/base.py                          10      4    60%
	 source_acceptance_test/config.py                        74      8    89%
	 source_acceptance_test/conftest.py                     108    108     0%
	 source_acceptance_test/plugin.py                        45     45     0%
	 source_acceptance_test/tests/__init__.py                 4      0   100%
	 source_acceptance_test/tests/test_core.py              158    109    31%
	 source_acceptance_test/tests/test_full_refresh.py       18     11    39%
	 source_acceptance_test/tests/test_incremental.py        69     38    45%
	 source_acceptance_test/utils/__init__.py                 6      0   100%
	 source_acceptance_test/utils/asserts.py                 37      2    95%
	 source_acceptance_test/utils/common.py                  41     25    39%
	 source_acceptance_test/utils/compare.py                 47     20    57%
	 source_acceptance_test/utils/connector_runner.py        82     49    40%
	 source_acceptance_test/utils/json_schema_helper.py      75     11    85%
	 ------------------------------------------------------------------------
	 TOTAL                                                  776    430    45%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                 Stmts   Miss  Cover
	 --------------------------------------------------------
	 unit_tests/unit_test.py::test_example_method �[32mPASSED�[0mCoverage.py warning: No data was collected. (no-data-collected)
	 source_salesforce/__init__.py            2      2     0%
	 source_salesforce/api.py               114    114     0%
	 source_salesforce/exceptions.py          1      1     0%
	 source_salesforce/rate_limiting.py      22     22     0%
	 source_salesforce/source.py             51     51     0%
	 source_salesforce/streams.py           201    201     0%
	 --------------------------------------------------------
	 TOTAL                                  391    391     0%

@jrhizor jrhizor temporarily deployed to more-secrets September 17, 2021 12:21 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets September 17, 2021 12:21 Inactive
@@ -186,7 +186,7 @@ def delete_job(self, url: str):

def next_page_token(self, last_record: dict) -> str:
if self.primary_key and self.name not in UNSUPPORTED_FILTERING_STREAMS:
return f"WHERE {self.primary_key} > '{last_record[self.primary_key]}' "
return f"WHERE {self.primary_key} >= '{last_record[self.primary_key]}' "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are PKs numeric and incremental? why are we not using cursor field here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for Full Refresh streams. It turned out that it is impossible to use Offset more than 2000 - Salesforce API swears at this, so I had to use the same method as for Incremental, only use ID, not cursor_field.

@@ -272,11 +272,12 @@ def read_records(

if job_status in ["JobComplete", "Aborted", "Failed"]:
self.delete_job(url=job_full_url)
pagination_complete = True
if job_status in ["Aborted", "Failed"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be raising exception if the job failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if len(response_data["records"]) == self.limit and self.primary_key and self.name not in UNSUPPORTED_FILTERING_STREAMS:
return f"WHERE {self.primary_key} > '{response_data['records'][-1][self.primary_key]}' "
if len(response_data["records"]) == self.page_size and self.primary_key and self.name not in UNSUPPORTED_FILTERING_STREAMS:
return f"WHERE {self.primary_key} >= '{response_data['records'][-1][self.primary_key]}' "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why aer we comparing PK and not cursor field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered in the comment above

@yevhenii-ldv
Copy link
Contributor Author

yevhenii-ldv commented Sep 20, 2021

/test connector=connectors/source-salesforce

🕑 connectors/source-salesforce https://github.com/airbytehq/airbyte/actions/runs/1253790524
✅ connectors/source-salesforce https://github.com/airbytehq/airbyte/actions/runs/1253790524
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                 Stmts   Miss  Cover
	 ------------------------------------------------------------------------
	 source_acceptance_test/__init__.py                       2      0   100%
	 source_acceptance_test/base.py                          10      4    60%
	 source_acceptance_test/config.py                        74      8    89%
	 source_acceptance_test/conftest.py                     108    108     0%
	 source_acceptance_test/plugin.py                        45     45     0%
	 source_acceptance_test/tests/__init__.py                 4      0   100%
	 source_acceptance_test/tests/test_core.py              158    109    31%
	 source_acceptance_test/tests/test_full_refresh.py       18     11    39%
	 source_acceptance_test/tests/test_incremental.py        69     38    45%
	 source_acceptance_test/utils/__init__.py                 6      0   100%
	 source_acceptance_test/utils/asserts.py                 37      2    95%
	 source_acceptance_test/utils/common.py                  41     25    39%
	 source_acceptance_test/utils/compare.py                 47     20    57%
	 source_acceptance_test/utils/connector_runner.py        82     49    40%
	 source_acceptance_test/utils/json_schema_helper.py      75     11    85%
	 ------------------------------------------------------------------------
	 TOTAL                                                  776    430    45%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                 Stmts   Miss  Cover
	 --------------------------------------------------------
	 source_salesforce/__init__.py            2      2     0%
	 source_salesforce/api.py               114    114     0%
	 source_salesforce/exceptions.py          1      1     0%
	 source_salesforce/rate_limiting.py      22     22     0%
	 source_salesforce/source.py             51     51     0%
	 source_salesforce/streams.py           201    201     0%
	 --------------------------------------------------------
	 TOTAL                                  391    391     0%

@jrhizor jrhizor temporarily deployed to more-secrets September 20, 2021 13:53 Inactive
@yevhenii-ldv
Copy link
Contributor Author

yevhenii-ldv commented Sep 21, 2021

/publish connector=connectors/source-salesforce

🕑 connectors/source-salesforce https://github.com/airbytehq/airbyte/actions/runs/1257403541
✅ connectors/source-salesforce https://github.com/airbytehq/airbyte/actions/runs/1257403541

@yevhenii-ldv yevhenii-ldv temporarily deployed to more-secrets September 21, 2021 11:34 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets September 21, 2021 11:35 Inactive
@yevhenii-ldv yevhenii-ldv merged commit c114ec8 into master Sep 21, 2021
@yevhenii-ldv yevhenii-ldv deleted the ykurochkin/salesforce-bug-with-bulk-pagination branch September 21, 2021 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Source-Salesforce: Bulk API limited to 10,000 records
5 participants