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

refactor(blocklist): separate utility function & kill switch for validating data in blocklist #3360

Merged
merged 35 commits into from
Feb 6, 2024

Conversation

prajjwalkumar17
Copy link
Contributor

@prajjwalkumar17 prajjwalkumar17 commented Jan 16, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Refactoring the way blocklist is written making the code separated into utility functions rather that being on the core flow itself.
Moreover this will allow us to enable and disable the blocklist feature based on each merchant's requirements.
The steps to test out this feature can be found in the mentioned issue.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

Screenshot 2024-01-18 at 17 20 10

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

@prajjwalkumar17 prajjwalkumar17 requested a review from a team as a code owner January 16, 2024 11:31
@prajjwalkumar17 prajjwalkumar17 marked this pull request as draft January 16, 2024 11:31
@prajjwalkumar17 prajjwalkumar17 self-assigned this Jan 18, 2024
@prajjwalkumar17 prajjwalkumar17 added A-core Area: Core flows S-waiting-on-review Status: This PR has been implemented and needs to be reviewed C-refactor Category: Refactor M-api-contract-changes Metadata: This PR involves API contract changes A-errors Area: error messages, structure & logging R-waiting-on-L1 Review: Waiting on L1 reviewer R-waiting-on-L2 Review: Waiting on L2 reviewer labels Jan 18, 2024
@prajjwalkumar17 prajjwalkumar17 added this to the December 2023 Release milestone Jan 18, 2024
@prajjwalkumar17 prajjwalkumar17 marked this pull request as ready for review January 18, 2024 11:50
@prajjwalkumar17 prajjwalkumar17 requested review from a team as code owners January 18, 2024 11:50
@prajjwalkumar17 prajjwalkumar17 mentioned this pull request Jan 19, 2024
15 tasks
@Narayanbhat166
Copy link
Member

Hey @vspecky, I feel that the error should be handled gracefully by passing a field or a flag saying that the payment method is blocked and all the further steps should read this value and skip the step if payment method is blocked, the status should then be updated in the payment_response_update_tracker. What do you feel about this?

@vspecky
Copy link
Member

vspecky commented Feb 5, 2024

Hey @vspecky, I feel that the error should be handled gracefully by passing a field or a flag saying that the payment method is blocked and all the further steps should read this value and skip the step if payment method is blocked, the status should then be updated in the payment_response_update_tracker. What do you feel about this?

@Narayanbhat166 I don't think there's an issue with early return. If we wanted to do it gracefully, we'd have to add guards everywhere in the subsequent flows in the form of if !blocked { do stuff and return data } else { return some default data }. I don't see a point in going through all that dev trouble and processing if we know we're gonna return an (irrecoverable) error at the end anyways.

vspecky
vspecky previously approved these changes Feb 5, 2024
@Narayanbhat166
Copy link
Member

@vspecky the problem lies in the way this error is raised, in fact this is not an application error, but we are made to handle it as an application error to short circuit the flow and save some of the dev effort.

@vspecky
Copy link
Member

vspecky commented Feb 6, 2024

@vspecky the problem lies in the way this error is raised, in fact this is not an application error, but we are made to handle it as an application error to short circuit the flow and save some of the dev effort.

@Narayanbhat166 That makes sense. In the first place, do we even want to send an error? We should probably be sending a PaymentsResponse with the status as failed right? (return Ok() from payments_operation_core)

Comment on lines +1256 to +1261
Err(inner) => {
if !inner.current_context().is_db_not_found() {
logger::error!("Error fetching guard blocklist enabled config {:?}", inner);
}
false
}
Copy link
Member

Choose a reason for hiding this comment

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

is this logic doing what you intend to do? There is a negation of the condition, and the return value is outside the if block.

Copy link
Member

Choose a reason for hiding this comment

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

raise database error if any other error other than DbNotFound is found

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Narayanbhat166 we already have major refactorings ongoing for the above feature, which will result in most of the code becoming depricated. So we can possibly do all refactorings in the upcoming PRs, as this is critical to go.

Comment on lines +1256 to +1261
Err(inner) => {
if !inner.current_context().is_db_not_found() {
logger::error!("Error fetching guard blocklist enabled config {:?}", inner);
}
false
}
Copy link
Member

Choose a reason for hiding this comment

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

raise database error if any other error other than DbNotFound is found

@likhinbopanna likhinbopanna added this pull request to the merge queue Feb 6, 2024
@prajjwalkumar17
Copy link
Contributor Author

prajjwalkumar17 commented Feb 6, 2024

Here are all the testing procedures to be followed.

Merged via the queue into main with commit 0a97a1e Feb 6, 2024
9 of 12 checks passed
@likhinbopanna likhinbopanna deleted the refactor_blocklist branch February 6, 2024 13:50
@prajjwalkumar17 prajjwalkumar17 removed S-waiting-on-review Status: This PR has been implemented and needs to be reviewed R-waiting-on-L1 Review: Waiting on L1 reviewer R-waiting-on-L2 Review: Waiting on L2 reviewer labels Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-errors Area: error messages, structure & logging C-refactor Category: Refactor M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants