Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Conversation

@rohitvinnakota-codecov
Copy link
Contributor

Purpose/Motivation

What is the feature? Why is this being done?

Links to relevant tickets

What does this PR do?

Include a brief description of the changes in this PR. Bullet points are your friend.

Notes to Reviewer

Anything to note to the team? Any tips on how to review, or where to start?

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@sentry
Copy link

sentry bot commented Mar 26, 2025

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: billing/views.py

Function Unhandled Issue
_check_and_handle_delayed_notification_payment_methods InvalidRequestError: Could not determine which URL to request: PaymentMethod instance has invalid ID: None, <class 'NoneType'>. ID should be of type str (or unicode) ...
Event Count: 13

Did you find this useful? React with a 👍 or 👎

@seer-by-sentry
Copy link
Contributor

seer-by-sentry bot commented Mar 26, 2025

🚨 Sentry detected 1 potential issue in your recent changes 🚨

  • Line 522, billing/views.py: Argument 2 to "_check_and_handle_delayed_notification_payment_methods" of "StripeWebhookHandler" has incompatible type "str | PaymentMethod | None"; expected "str"

    • payment_method_id can be None, causing Stripe API calls to fail due to an invalid PaymentMethod ID.
    • This may cause issues similar to: #6308720832

Did you find this useful? React with a 👍 or 👎

@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer test

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 26, 2025

On it! Codecov is generating unit tests for this PR.

@codecov-notifications
Copy link

codecov-notifications bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 0% with 104 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
api/gen_ai/math.py 0.00% 104 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codecov
Copy link

codecov bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 0% with 104 lines in your changes missing coverage. Please review.

Project coverage is 94.75%. Comparing base (3b18f44) to head (0fc4bd8).
Report is 3 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
api/gen_ai/math.py 0.00% 104 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1245      +/-   ##
==========================================
- Coverage   96.31%   94.75%   -1.57%     
==========================================
  Files         492      493       +1     
  Lines       16844    16931      +87     
==========================================
- Hits        16224    16043     -181     
- Misses        620      888     +268     
Flag Coverage Δ
unit 94.75% <0.00%> (-1.57%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-ai codecov-ai bot mentioned this pull request Mar 26, 2025
@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer test

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 26, 2025

On it! Codecov is generating unit tests for this PR.

@codecov-ai codecov-ai bot mentioned this pull request Mar 26, 2025
@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer test

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 26, 2025

On it! Codecov is generating unit tests for this PR.

@codecov-ai codecov-ai bot mentioned this pull request Mar 26, 2025
@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer review

2 similar comments
@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer review

@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer review

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 27, 2025

On it! We are reviewing the PR and will provide feedback shortly.

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 27, 2025

No changes requiring review at this time.

@rohitvinnakota-codecov
Copy link
Contributor Author

@codecov-ai-reviewer review

@codecov-ai
Copy link
Contributor

codecov-ai bot commented Mar 28, 2025

On it! We are reviewing the PR and will provide feedback shortly.

Comment on lines +17 to +24
# Factorial using iterative approach
def factorial(n):
if n < 0:
raise ValueError("Negative numbers do not have factorials")
result = 1
for i in range(1, n + 1):
result *= i
return result
Copy link
Contributor

Choose a reason for hiding this comment

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

The factorial implementation currently uses an iterative approach which could encounter stack overflow for large numbers. Consider adding a maximum input validation to prevent potential resource exhaustion attacks. Also, consider documenting the maximum supported input value in the docstring.

Suggested change
# Factorial using iterative approach
def factorial(n):
if n < 0:
raise ValueError("Negative numbers do not have factorials")
result = 1
for i in range(1, n + 1):
result *= i
return result
def factorial(n):
if n < 0:
raise ValueError("Negative numbers do not have factorials")
if n > 900: # Prevent stack overflow/resource exhaustion
raise ValueError("Input too large. Maximum supported value is 900")
result = 1
for i in range(1, n + 1):
result *= i
return result

Comment on lines +102 to +110
raise ValueError("At least two data points are required to compute variance")
return variance(self.data)

def normalize(self):
m = self.get_mean()
try:
std_dev = math.sqrt(variance(self.data))
except Exception:
raise ValueError("Could not compute standard deviation")
Copy link
Contributor

Choose a reason for hiding this comment

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

The normalize method in DataProcessor is not handling potential division by zero correctly. While there is a check for std_dev == 0, the sqrt operation could still raise a ValueError. Consider adding proper error handling and documentation about expected behavior in edge cases.

Suggested change
raise ValueError("At least two data points are required to compute variance")
return variance(self.data)
def normalize(self):
m = self.get_mean()
try:
std_dev = math.sqrt(variance(self.data))
except Exception:
raise ValueError("Could not compute standard deviation")
def normalize(self):
m = self.get_mean()
try:
std_dev = math.sqrt(self.get_variance())
if std_dev == 0:
raise ValueError("Standard deviation is zero, cannot normalize.")
return [(x - m) / std_dev for x in self.data]
except ValueError as e:
raise ValueError(f"Normalization failed: {str(e)}")

Comment on lines +127 to +134
return default

# Merge two dictionaries recursively
def merge_dicts(dict1, dict2):
result = dict1.copy()
for key, value in dict2.items():
if key in result and isinstance(result[key], dict) and isinstance(value, dict):
result[key] = merge_dicts(result[key], value)
Copy link
Contributor

Choose a reason for hiding this comment

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

The merge_dicts function could potentially cause runtime errors with very deep dictionaries due to recursive calls. Consider adding a depth limit parameter and check to prevent stack overflow in case of maliciously crafted input.

Suggested change
return default
# Merge two dictionaries recursively
def merge_dicts(dict1, dict2):
result = dict1.copy()
for key, value in dict2.items():
if key in result and isinstance(result[key], dict) and isinstance(value, dict):
result[key] = merge_dicts(result[key], value)
def merge_dicts(dict1, dict2, max_depth=10, current_depth=0):
if current_depth >= max_depth:
raise ValueError(f"Maximum merge depth of {max_depth} exceeded")
result = dict1.copy()
for key, value in dict2.items():
if key in result and isinstance(result[key], dict) and isinstance(value, dict):
result[key] = merge_dicts(result[key], value, max_depth, current_depth + 1)
else:
result[key] = value
return result

Comment on lines 73 to 76
)

def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
"""
Stripe invoice.payment_failed webhook event is emitted when an invoice payment fails
(initial or recurring). Note that delayed payment methods (including ACH with
microdeposits) may have a failed initial invoice until the account is verified.
"""
if invoice.default_payment_method is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

The deletion of extensive documentation in the webhook handlers significantly reduces code maintainability. Even if the functionality is being moved or refactored, it's important to maintain clear documentation about the webhook purposes and behaviors. Consider retaining or updating the docstrings.

Suggested change
)
def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
"""
Stripe invoice.payment_failed webhook event is emitted when an invoice payment fails
(initial or recurring). Note that delayed payment methods (including ACH with
microdeposits) may have a failed initial invoice until the account is verified.
"""
if invoice.default_payment_method is None:
def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
"""Handles Stripe invoice.payment_failed webhook events.
Called when an invoice payment fails (initial or recurring). Note that delayed
payment methods (including ACH with microdeposits) may have a failed initial
invoice until the account is verified.
Args:
invoice: The Stripe invoice object containing payment details
"""

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants