-
Notifications
You must be signed in to change notification settings - Fork 47
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
TDL-19384 optimize logic for parent child relationship to be independent #141
TDL-19384 optimize logic for parent child relationship to be independent #141
Conversation
tap_stripe/__init__.py
Outdated
""" | ||
LOGGER.info("Started syncing stream %s", stream_name) | ||
|
||
stream_metadata = metadata.to_map(Context.get_catalog_entry(stream_name)['metadata']) | ||
stream_field_whitelist = json.loads(Context.config.get('whitelist_map', '{}')).get(stream_name) | ||
|
||
extraction_time = singer.utils.now() | ||
replication_key = metadata.get(stream_metadata, (), 'valid-replication-keys')[0] | ||
if is_sub_stream: | ||
# We need to change the parent, when only child is selected, hence need to change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namrata270998 can you please rewrite this comment as follows
# We need to change the parent, when only child is selected, hence need to change | |
# We need to get the parent data first for syncing the child streams. Hence, changing stream_name to parent stream when only child is selected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the comment
tap_stripe/__init__.py
Outdated
# We need to change the parent, when only child is selected, hence need to change | ||
# stream_name to its parent. | ||
stream_name = PARENT_STREAM_MAP.get(stream_name) | ||
replication_key = STREAM_REPLICATION_KEY.get(stream_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namrata270998 Optimization and Readability:
if is_sub_stream:
sub_stream_name = stream_name
stream_name = PARENT_STREAM_MAP.get(stream_name)
replication_key = STREAM_REPLICATION_KEY.get(stream_name)
You can remove the code at L578
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Updated the code
- Also We cannot remove the L578 as if both parent and child would be selected, we'll need the sub_stream_name for fetching the child records.
stream_name = PARENT_STREAM_MAP[stream_name] | ||
stream_name = PARENT_STREAM_MAP.get(sub_stream_name) | ||
|
||
sub_stream_name = SUB_STREAMS.get(stream_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namrata270998 This line overwrites L918. What is the need of this line explicitly?
If this function is called by sub-stream, we assign value to this variable at L918. Else, we keep it None as default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not keep it None as default, as if both parent and child would be selected, we'll need the sub_stream_name for fetching the child records.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. can you remove L919 as it would not have any use? It will always get overridden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the line as it will be overriden
invoice_line_items_ts = 1641137533 | ||
Context.state = {"bookmarks": {"invoices": {"date": 1645716195}, "invoice_line_items": {"date": invoice_line_items_ts}}} | ||
invoice_line_items_ts = 1641137533 # 02-01-2022T03:32:13Z | ||
Context.state = {"bookmarks": {"invoices": {"date": 1641137533}, "invoice_line_items": {"date": invoice_line_items_ts}}} | ||
sync() | ||
stop_window = dt_to_epoch(now_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namrata270998 is there a reason for explicitly setting stop_window
? I think we can expect that value of stop_window
should be start_date + 30 days by default. This way we will check the window logic as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we keep the stop window 30 days, still the loop will execute one time, and as we just want to check that the bookmark is used properly we can keep any stop window, it will not affect anywhere in this testcase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand. However, it would be good if we check the routine scenarios in the test case rather than mocking it unneccesarily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the stop window to take 30 days time window
''' | ||
Verify that state is updated with parent's bookmark after syncing the child. | ||
Verify that event_updates is called for child stream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we not check this case in the above function itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the above test case we checked for child bookmarking, and in the current we are checking for events bookmarks. Also we need to mock different things in both of them and the scenarios are different, hence kept them separate
* TDL-14058: Update SDK and api version (#105) * Updated SDK and API version * Added expand parameter for more streams * Updated replication key for invoices * added backward compability for invoice bookmark * Added unit test and code coverage report in circleci * Resolved unit test failure * Updated stripe SDK to latest version * Running all test for testing * updated stripe version in config.yml * Running all test for testing * Running all test for testing * Running all test for testing * Updated base class of tap_tester to handle replication key change of invoices * Reverted back config.yml to run dependant tests * Reverted back config.yml to run dependant tests * Updated all_field test case * Added back payout stream * Added comments in test case * Fixed key in bookmark for invoice_line_items * Fixed key in bookmark for invoice_line_items in get_bookmark * Fixed charge stream for all_field test case * Fixed payouts stream for all_field test case * Updated amount value * Resolved circleci error * Fiexed all_field test case�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[D�[�[�[3~�[�[C�[�[C�[C�[C�[C�[C�[C�[C�[C�[C�[C�[C�[C�[C�[C�[C�[xed invoice_line_item failure in all_field test case * Fix the build_daily workflow definition * Resolved review comment * Updated all_field test case * Updated test case for customer and invoice_line_item stream * Updated util.py * Removed fields from missing fields * fixed subscription_items stream * Resolved review comment and added function for get and write bookmark * Updated code comment * Tdl 5894 update invoices stream (#115) * initial commit * added back for all streams * resolved comments * fixed cci errors * fixed typo in comment * updated comment * fixed typo in function * fixed failures * fixed error * resolved failure for discount * updated discount schema * added bugtracker * Tdl 6026 Modify 'customer' stream on 'test_all_fields.py' to pass (#109) * Initial commit * Updated util.py �[D�[D�[D�[D�[D�[D�[D�[DAPI version to latest in util.py * Added support of tax_ids field * Updated discount schema * Updated datatype of percent_off field. * Tdl 6597 Modify 'product' stream on 'test_all_fields.py' to pass (#108) * Initial commit * Added back schema_keys * Uncommented expected assertion * Removed skus field from schema * TDL-6587 Modify 'invoice_line_items' stream on 'test_all_fields.py' to pass (#112) * Initial commit * Updated schema file * Removed price field from schema * Removed tax_rates from schema * Removed extra fields from schema * Updated schema file * Added metadata in schema * Added invoice_line_items in KNOWN_FAILING_FIELDS * Updated price value�[D�[D�[D�[D�[Drecord value * Updated all_field test case * Merged changes * Uncommented code * Updated code comment * TDL-5992 modify subscription items stream (#114) * initial commit with subscription_items stream * reverted back to all streams * resolved pylint * testing for subscription_items only * resolved error * added back for all streams * resolved cci errors * added commnets * added automatic fields for subscription items * removed updated from the schema * removed empty line and updated base * resolved comments * chahnged updated * reverted changes * reverted changes * removed updated from subscription_items * reverted a type change Co-authored-by: prijendev <[email protected]> * TDL-17429 Revert back tiers field datatype conversion (#117) * Initial commit for dict to stripe object conversion * Resolved pylint error * Updated test cases * Added condtion to check dict type Co-authored-by: prijendev <[email protected]> Co-authored-by: namrata270998 <[email protected]> Co-authored-by: namrata270998 <[email protected]> Co-authored-by: Prijen Khokhani <[email protected]> * Added tax_type and metadata in subcriptions_items * added the proration_details due to cci failure * TDL-17880 Add missing test cases (#131) * Added event_type field in all schemas * Added test cases for event updates * Updated __init__ file * Updated event_type field to updated_by_event_type field name * Reverted back config.yml file changes * Updated event_type field in all_field test case. * Added missing test case assertion * fixed circleci error and updated tests * updated integration tests to resolve cci failures * removed the unused variables * removed duplicate code * resolved comments * added more comments * added new map for intermittent missing fields * updated schema missing fields map and changed the union * added proper comment Co-authored-by: prijendev <[email protected]> Co-authored-by: nevilparikh_crest <[email protected]> * Tdl 13149 sync payment intent (#127) * Initial commit for payment_intent stream * Updated bookmark test case. * Updated expand parameter for charge stream in utils.py * Updated utils.py * Removed payment_intent object from charge stream * Removed extra field from charges schema * Added card field in schema * Updated transfer_group and application_fee_amount field type * Updated transfer_group field * Updated datatype of destination field * Updated transfer_data * Added payment record creation * Resolved test case error * Resloved all fields test case error * Resolved test case error * Added comments in test case. Co-authored-by: namrata270998 <[email protected]> * Tdl 13711 upgrade json schema (#124) * updated the transform_usage type and integration tests * added plan back to the sub_items * removed the workaround for the invoices 'created' field * updated transform_usage type * added code comment * TDL 15120 add event type field in schemas (#123) * Added event_type field in all schemas * Added test cases for event updates * Updated __init__ file * Updated event_type field to updated_by_event_type field name * Reverted back config.yml file changes * Updated event_type field in all_field test case. Co-authored-by: namrata270998 <[email protected]> * updated charge.json * TDL-14354 log request_id (#135) * logged request_id for the sdk calls * unittests for debug log * changed the logic of new_list and updated unittests * added code comments * rsolved pylint error * resolved cci failures * resolved pylint errors * rsolved pylint * changed the function overwritten for logging request id * resolved PR review comments * skipped schema missing fields to pass the cci * fixed cci issue * added schema missing fields * added receipt_url in fickle fields * resolved PR comments * TDL-17879 added authentication before discovery mode and unittests (#128) * added authentication before discovery mode and unittests * resolved comments * fixed spelling error * added schema missing fields * added comment for pagination test * added detailed comment * added ticket it * fixed circleci errors * Tdl 17878 implement request timeout and retry (#126) * added configurable request timeout with default as 5 minutes * added comments * added schema missing fields missing from schema * fixed cci error * added timeout in readme * TDL-9856: ensure setup includes non-automatic balance transactions (#129) * added test case to verify we sync only automatic payout's transactions * added more comments * resolved PR review comments * resolve CCi error * added doc-string in test_automatic_payout_transactions * resolve CCi error * resolve CCi error * resolve CCi error * resolve CCi error * added try-catch in test_automatic_payout_transactions Co-authored-by: namrata270998 <[email protected]> * TDL-16966: Handle deleted invoice_line_items returned from the events updates endpoint (#137) * Added retry logic for deleted invoice line items * Resolved pylint error * Added backoff over child also * added code to skip deleted invoice line item call * resolved unittest failure * Updated all field test case. * Reverted back changes in base.py * Updated all field test case to pass cci. Co-authored-by: harshpatel4_crest <[email protected]> Co-authored-by: namrata270998 <[email protected]> * TDL-15168: Use `unique_line_item_id` for invoice updates' lines value instead of `id` (#134) * updated id field for invoice line items * resolve integration test error * updated code to handle null invoice_item for invoice line items * resolve review comments * resolved CCi failure Co-authored-by: namrata270998 <[email protected]> * TDL-9801: `payouts` incorrectly mapped to `transfers` object results in transfer objects replicated by payouts stream (#133) * added payout with transfer for payout events * updated config.yml file * removed unnecessary files * resolved integration test error * resolved integration test error * resolved review comments * fix integration test and run all fields test only * fix cci failure * fix cci failure * fix cci failure * fix cci failure, run all tests Co-authored-by: namrata270998 <[email protected]> * Tdl 17902 fix parent child relationship (#130) * update child bookmark and make child stream independent * fixed pylint * resolved PR review comments * added function comments * added child streams to bookmarks test and added a comment to all_fields * resolved cci error * resolved comments * resolved comments * resolved PR review comments * fixed circleci errors * skipped schema missing fields and removed extra checks for nested fields * skipped receipt_url as it keeps changing every time in all_fields * updated function name in unittest and resolved pylint error (#140) Updated function names of unittest after all PR merge. * TDL-18217 change lookback window logic (#138) * added configurable lookback window * added code comments * resolved comments * resolved comments * changed lookback and added integration test * added new map for intermittently missing fields * resolved events stream lookback issue * updated schema missing fields map * added lookback test in config.yml * initial commit * configurable lookback window for bothstreams with updated tests * resolved cci issue and added new assertion * fixed cci issues * addentsd comme * added lookback test in all_tests_run * changed to same default lookback for both streams * resolved PR review comments * fixed typo error * added code comments * changed the lookback loguc acc to Kyle's suggestions * updated comments * float value in lookback * removed float as giving error * handled 0 scenario for lookback * handled string 0 and fixed cci * resolved comments * skipped new fields not present in schema fields to fix cci * resolved comments * added comments in unittests * added lookback in readme * updated debug with %s instead of f-string * updated unittests for the logger statement * removed the timedelta from start_date in lookback_window test * added all_fields in lookback test deoendency * updated the configurable lookback window test * TDL-19384 optimize logic for parent child relationship to be independent (#141) * initial commit with optimized logic for parent child streams * fixed issues in the invoices and invoice_line_items sync * fixed pylint * updated unittests * TDL-19384: Added Sub Stream check * fixed unittests * resolved PR comments and fix cci issues * updated invoice_line_item to line_item * Updated the code comments * fixed typo * updated code comments and added more unittests * resolved pylint * removed uwanted comments * resolved PR comments * resolved PR comments * resolved PR review comments * added integration test for only parent * resolved PR comments * skipped some newly generated fields from all_fields * added failing field as missing nested field Co-authored-by: dbshah1212 <[email protected]> * removed skipped fields from SCHEMA_MISSING_FIELDS * added missing fields in skipped fields Co-authored-by: savan-chovatiya <[email protected]> Co-authored-by: namrata270998 <[email protected]> Co-authored-by: namrata270998 <[email protected]> Co-authored-by: nevilparikh_crest <[email protected]> Co-authored-by: Harsh <[email protected]> Co-authored-by: harshpatel4_crest <[email protected]> Co-authored-by: dbshah1212 <[email protected]>
Description of change
Manual QA steps
Risks
Rollback steps