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

ValueError at /attendance/work-record-export/ invalid literal for int() with base 10: '' #446

Open
rizwanhaiderhero opened this issue Dec 31, 2024 · 5 comments

Comments

@rizwanhaiderhero
Copy link

Bug Report

I'm facing this error while exporting work records from attendance

Environment:

Request Method: GET
Request URL: http://localhost:8000/attendance/work-record-export/?month=&year=&

Django Version: 4.2.11
Python Version: 3.9.6
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'notifications',
'mathfilters',
'corsheaders',
'simple_history',
'django_filters',
'base',
'employee',
'recruitment',
'leave',
'pms',
'onboarding',
'asset',
'attendance',
'payroll',
'widget_tweaks',
'django_apscheduler',
'accessibility',
'horilla_audit',
'horilla_widgets',
'horilla_crumbs',
'horilla_documents',
'haystack',
'horilla_views',
'horilla_automations',
'auditlog',
'biometric',
'helpdesk',
'offboarding',
'rest_framework',
'rest_framework_simplejwt',
'drf_yasg',
'horilla_api']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'corsheaders.middleware.CorsMiddleware',
'simple_history.middleware.HistoryRequestMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'auditlog.middleware.AuditlogMiddleware',
'base.middleware.CompanyMiddleware',
'horilla.horilla_middlewares.MethodNotAllowedMiddleware',
'horilla.horilla_middlewares.ThreadLocalMiddleware',
'accessibility.middlewares.AccessibilityMiddleware',
'accessibility.middlewares.AccessibilityMiddleware',
'base.middleware.ForcePasswordChangeMiddleware',
'attendance.middleware.AttendanceMiddleware']

Traceback (most recent call last):
File "/Users/rizwanhaider/PycharmProjects/horilla/horilla/decorators.py", line 234, in wrapped_view
func = view_func(request, *args, **kwargs)
File "/Users/rizwanhaider/PycharmProjects/horilla/horilla/decorators.py", line 41, in _function
return function(request, *args, **kwargs)
File "/Users/rizwanhaider/PycharmProjects/horilla/attendance/views/views.py", line 2360, in work_record_export
month = int(request.GET.get("month", date.today().month))

During handling of the above exception (invalid literal for int() with base 10: ''), another exception occurred:
File "/Users/rizwanhaider/PycharmProjects/horilla/horillavenv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/Users/rizwanhaider/PycharmProjects/horilla/horillavenv/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/rizwanhaider/PycharmProjects/horilla/horilla/decorators.py", line 249, in wrapped_view
return view_func(request, *args, **kwargs)
File "/Users/rizwanhaider/PycharmProjects/horilla/horilla/decorators.py", line 41, in _function
return function(request, *args, **kwargs)
File "/Users/rizwanhaider/PycharmProjects/horilla/attendance/views/views.py", line 2360, in work_record_export
month = int(request.GET.get("month", date.today().month))

Exception Type: ValueError at /attendance/work-record-export/
Exception Value: invalid literal for int() with base 10: ''

@horilla-opensource
Copy link
Owner

Hi @rizwanhaiderhero ,

The error occurred because the month parameter was being processed without checking if it was empty, leading to a ValueError.

We’ve updated the source code to handle this scenario more gracefully by ensuring proper validation of the input parameters. If the month or year parameters are missing or empty, a default value is now applied, and any invalid input is handled appropriately.

Please pull the latest changes from the repository, and this issue should be resolved. Let us know if you encounter any further problems

With Regards,
Team Horilla

@rizwanhaiderhero
Copy link
Author

i think the actual issue is
Month and year are already selected you can check in the screenshot so adding try and catch is just a bypass solution not the permanent
Screenshot 2024-12-31 at 6 43 06 PM

@rizwanhaiderhero
Copy link
Author

get method was used it means whatever month and year is selected
URl should be like http://localhost:8000/attendance/work-record-export/?month=12&year=2024&
but instead it was empty http://localhost:8000/attendance/work-record-export/?month=&year=&

@horilla-opensource
Copy link
Owner

Hi @rizwanhaiderhero,

Thanks for the feedback. Could you provide more details or a short video demonstrating the issue to our mail [email protected] ? This will help us understand the exact scenario and implement a permanent solution.

Best regards,
Team Horilla

@rizwanhaiderhero
Copy link
Author

rizwanhaiderhero commented Jan 6, 2025 via email

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

No branches or pull requests

2 participants