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: Explicitly cast upload memory size config values to integers #1138

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

trent-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.

@codecov-notifications
Copy link

codecov-notifications bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.07%. Comparing base (ca253c1) to head (c969405).
Report is 19 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1138   +/-   ##
=======================================
  Coverage   96.07%   96.07%           
=======================================
  Files         837      837           
  Lines       19856    19856           
=======================================
  Hits        19076    19076           
  Misses        780      780           
Flag Coverage Δ
unit 95.97% <100.00%> (ø)
unit-latest-uploader 95.97% <100.00%> (ø)

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-qa
Copy link

codecov-qa bot commented Feb 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.97%. Comparing base (ca253c1) to head (c969405).
Report is 19 commits behind head on main.

✅ All tests successful. No failed tests found.

Copy link
Contributor

github-actions bot commented Feb 6, 2025

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@Adal3n3
Copy link

Adal3n3 commented Feb 6, 2025

@codecov-ai-reviewer review

Copy link

codecov-ai bot commented Feb 6, 2025

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

Comment on lines 347 to +349

DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
Copy link

Choose a reason for hiding this comment

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

Good change. Converting the configuration value to an integer ensures type consistency and prevents potential issues with non-integer values. However, consider adding error handling in case the conversion fails.

Suggested change
DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
try:
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
except ValueError:
DATA_UPLOAD_MAX_MEMORY_SIZE = 2621440 # Default value if conversion fails
logging.warning("Invalid value for DATA_UPLOAD_MAX_MEMORY_SIZE. Using default.")

Comment on lines 350 to +352
)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
Copy link

Choose a reason for hiding this comment

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

Similar to the previous comment, this is a good change for type consistency. Consider applying the same error handling approach here as well.

Suggested change
)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
)
try:
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
)
except ValueError:
FILE_UPLOAD_MAX_MEMORY_SIZE = 2621440 # Default value if conversion fails
logging.warning("Invalid value for FILE_UPLOAD_MAX_MEMORY_SIZE. Using default.")

Comment on lines 347 to +352

DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
Copy link

Choose a reason for hiding this comment

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

Consider adding a comment explaining why these values are being explicitly converted to integers. This will help future developers understand the reasoning behind the change.

Suggested change
DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
# Explicitly convert upload size limits to integers to ensure type consistency
# and prevent issues with non-integer values from configuration
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
)

Comment on lines 347 to +352

DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
Copy link

Choose a reason for hiding this comment

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

These configuration values are critical for controlling upload sizes. Consider adding validation to ensure the values are within an acceptable range to prevent potential security issues or resource exhaustion.

Suggested change
DATA_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "upload_max_memory_size", default=2621440
DATA_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
)
FILE_UPLOAD_MAX_MEMORY_SIZE = get_config(
"setup", "http", "file_upload_max_memory_size", default=2621440
FILE_UPLOAD_MAX_MEMORY_SIZE = int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
def validate_upload_size(size, min_size=1024, max_size=10485760):
if min_size <= size <= max_size:
return size
return max_size # Or min_size, depending on your preference
DATA_UPLOAD_MAX_MEMORY_SIZE = validate_upload_size(int(
get_config("setup", "http", "upload_max_memory_size", default=2621440)
))
FILE_UPLOAD_MAX_MEMORY_SIZE = validate_upload_size(int(
get_config("setup", "http", "file_upload_max_memory_size", default=2621440)
))

Copy link
Contributor

@adrian-codecov adrian-codecov left a comment

Choose a reason for hiding this comment

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

You still need this?

@trent-codecov trent-codecov added this pull request to the merge queue Feb 13, 2025
Merged via the queue into main with commit 7c058c9 Feb 13, 2025
19 checks passed
@trent-codecov trent-codecov deleted the trent/cast-settings branch February 13, 2025 19:27
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