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 age handling in buggy_code function #1258

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/seer/automation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,40 @@
from celery_app.app import celery_app
from seer.db import DbIssueSummary, DbRunState, Session


logger = logging.getLogger(__name__)

def safe_int_conversion(value, default=0):
"""
Safely convert a value to an integer.
Returns the default value if conversion is not possible.
"""
if value is None:
return default
try:
return int(value)
except ValueError:
logger.warning(f"Could not convert '{value}' to int. Using default: {default}")
return default

@celery_app.task(time_limit=30)
def buggy_code():
user_data = [
{"name": "Alice", "age": 30},
{"name": "Bob", "age": "25"},
{"name": "Bob", "age": 25},
{"name": "Charlie", "age": None},
{"name": "David", "age": 40},
]

for user in user_data:
print(user["age"] * 12) # type: ignore[index]
age = safe_int_conversion(user["age"])
monthly_age = age * 12
logger.info(f"User: {user['name']}, Age in months: {monthly_age}")

return [
{"name": user["name"], "age_in_months": safe_int_conversion(user["age"]) * 12}
for user in user_data
]

@celery_app.task(time_limit=30)
def delete_data_for_ttl():
Expand Down
Loading