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: unsupported operand type for remaining balance #262

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

sameenfatima78
Copy link
Member

@sameenfatima78 sameenfatima78 commented Sep 13, 2023

This change handles the scenario when spent_amount comes to be None.

@sameenfatima78 sameenfatima78 force-pushed the sameen/fix-unsupported-operand-type branch from 9326113 to 0a3e7d0 Compare September 13, 2023 18:10
@sameenfatima78
Copy link
Member Author

@adamstankiewicz Thanks for the suggestion, I have made the changes. Can you please review again?

Also, do you think it would make sense to move the "credit_available" method to the parent class as their definitions in both child classes are identical?

@sameenfatima78
Copy link
Member Author

@adamstankiewicz Reminder to please take a look into this on priority. This change is required by this PR that is already merged and deployed on stage but I am waiting to deploy it on prod.

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

Also, do you think it would make sense to move the "credit_available" method to the parent class as their definitions in both child classes are identical?

Hm, good question. Based on the other review comment about the credit_available methods, I think there might be an opportunity to abstract some common/generic checks used across both policy types' credit_available method (e.g., did the policy exceed its configured spend_limit?), but I might recommend keeping the per-learner checks separate as one's "remaining balance" deals with enrollment counts and the other's "remaining balance" deals with spend (money), which are fundamentally two different constructs that might have divergent behavior.

if self.remaining_balance_per_user(lms_user_id) > 0:
return True
return False
remaining_balance_per_user = self.remaining_balance_per_user(lms_user_id) or 0
Copy link
Member

@adamstankiewicz adamstankiewicz Sep 14, 2023

Choose a reason for hiding this comment

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

Similar to handling None versus 0 differently in the remaining_balance_per_user methods, the None or 0 should likely be handled as semantically different here as well.

If self.remaining_balance_per_user returns None because there is no self.per_learner_enrollment_limit set, I don't believe it's semantically correct to fallback to say the user has a remaining balance of 0, as there is no per-learner limit (this method would return False currently, even when there is no limit set).

Related, are there additional checks that are relevant to determine whether these policies are "available" beyond only checking against the per-learner limits? Would cases such as the following be handled by these credit_available methods?

  • User hasn't exceeded their individual per-learner limit, but the policy has already exceeded its configured spend_limit (not redeemable).
  • User hasn't exceeded their individual per-learner limit, but the associated subsidy has no remaining balance.
  • User hasn't exceeded their individual per-learner limit, but the policy is no longer active.
  • User hasn't exceeded their individual per-learner limit, but the associated subsidy is expired.

These are some of the additional checks that the can_redeem methods perform that might be worth referring to. Just verifying that the credits_available API is taking into account all factors that could deem a policy available or unavailable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Similar to handling None versus 0 differently in the remaining_balance_per_user methods, the None or 0 should likely be handled as semantically different here as well.

If self.remaining_balance_per_user returns None because there is no self.per_learner_enrollment_limit set, I don't believe it's semantically correct to fallback to say the user has a remaining balance of 0, as there is no per-learner limit (this method would return False currently, even when there is no limit set).

@adamstankiewicz Agreed. I have handled that part in the new changes.

Related, are there additional checks that are relevant to determine whether these policies are "available" beyond only checking against the per-learner limits? Would cases such as the following be handled by these credit_available methods?

User hasn't exceeded their individual per-learner limit, but the policy has already exceeded its configured spend_limit (not redeemable).
User hasn't exceeded their individual per-learner limit, but the associated subsidy has no remaining balance.
User hasn't exceeded their individual per-learner limit, but the policy is no longer active.
User hasn't exceeded their individual per-learner limit, but the associated subsidy is expired.
These are some of the additional checks that the can_redeem methods perform that might be worth referring to. Just verifying that the credits_available API is taking into account all factors that could deem a policy available or unavailable.

@adamstankiewicz I believe the existing code doesn't check any of these conditions. Would it be okay if I create a follow up ticket/PR to address this feedback as all of these checks would require adding unit tests..

Copy link
Member

Choose a reason for hiding this comment

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

@adamstankiewicz I believe the existing code doesn't check any of these conditions. Would it be okay if I create a follow up ticket/PR to address this feedback as all of these checks would require adding unit tests..

Yep, totally. Just wanted to call out that the current logic may not be fully taking into account all factors.

remove int from transaction count

incorporated feedback

incorporated feedback round two

incorporated feedback round 3
@sameenfatima78
Copy link
Member Author

@adamstankiewicz Gentle reminder to review this PR and if all looks good, please merge it.

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

LGTM. :shipit:

@sameenfatima78
Copy link
Member Author

@adamstankiewicz Thanks for the approval. Can you also please merge it? I don't seem to have the right access.

@adamstankiewicz adamstankiewicz merged commit 927f5dd into main Sep 18, 2023
3 checks passed
@adamstankiewicz adamstankiewicz deleted the sameen/fix-unsupported-operand-type branch September 18, 2023 19:09
@adamstankiewicz
Copy link
Member

adamstankiewicz commented Sep 18, 2023

@adamstankiewicz Thanks for the approval. Can you also please merge it? I don't seem to have the right access.

Merged! Edit: That is odd about the lack of merge permissions on your end...

@sameenfatima78
Copy link
Member Author

@adamstankiewicz Yeah, I believe it's the same for everyone in Markhors. 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants