horilla-opensource / horilla

Horilla is a free and open source HR software.
https://www.horilla.com/
GNU Lesser General Public License v2.1
198 stars 137 forks source link

Error when importing holidays from excel #302

Closed semor-joe closed 1 month ago

semor-joe commented 2 months ago

Bug Report

Description

Error when importing holidays from excel.

Logl

Screenshots

image image

Environment

Request Method: POST
Request URL: http://holiday.semorai.org/holidays-info-import

Django Version: 4.2.11
Python Version: 3.10.14
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',
 'horilla_audit',
 'horilla_widgets',
 'horilla_crumbs',
 'horilla_documents',
 'haystack',
 'horilla_views',
 'horilla_automations',
 'auditlog',
 'biometric',
 'helpdesk',
 'offboarding']
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',
 'attendance.middleware.AttendanceMiddleware']

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)

The above exception (value too long for type character varying(30)
) was the direct cause of the following exception:
  File "/app/base/views.py", line 6232, in holidays_info_import
    holiday.save()
  File "/app/horilla/models.py", line 100, in save
    super(HorillaModel, self).save(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 814, in save
    self.save_base(
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 877, in save_base
    updated = self._save_table(
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 1020, in _save_table
    results = self._do_insert(
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 1061, in _do_insert
    return manager._insert(
  File "/usr/local/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 1805, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/usr/local/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)

During handling of the above exception (value too long for type character varying(30)
), another exception occurred:
  File "/app/horilla/decorators.py", line 234, in wrapped_view
    func = view_func(request, *args, **kwargs)
  File "/app/horilla/decorators.py", line 41, in _function
    return function(request, *args, **kwargs)
  File "/app/base/views.py", line 6236, in holidays_info_import
    holiday["Error4"] = f"{str(e)}"

During handling of the above exception ('Holidays' object does not support item assignment), another exception occurred:
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)

The above exception (value too long for type character varying(30)
) was the direct cause of the following exception:
  File "/app/base/views.py", line 6232, in holidays_info_import
    holiday.save()
  File "/app/horilla/models.py", line 100, in save
    super(HorillaModel, self).save(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 814, in save
    self.save_base(
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 877, in save_base
    updated = self._save_table(
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 1020, in _save_table
    results = self._do_insert(
  File "/usr/local/lib/python3.10/site-packages/django/db/models/base.py", line 1061, in _do_insert
    return manager._insert(
  File "/usr/local/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 1805, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/usr/local/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)

During handling of the above exception (value too long for type character varying(30)
), another exception occurred:
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/app/horilla/decorators.py", line 249, in wrapped_view
    return view_func(request, *args, **kwargs)
  File "/app/horilla/decorators.py", line 41, in _function
    return function(request, *args, **kwargs)
  File "/app/base/views.py", line 6236, in holidays_info_import
    holiday["Error4"] = f"{str(e)}"

Exception Type: TypeError at /holidays-info-import
Exception Value: 'Holidays' object does not support item assignment
horilla-opensource commented 2 months ago

Hi @semor-joe , Is it possible for you to share the holidays import excel sheet to try it out from our end? We were able to successfully import the data into our system with our demo sheet.

With Regards, Team Horilla

semor-joe commented 2 months ago

holiday_excel_import.xlsx Hi Horilla-Team,

here is the excel.

Thank you!

horilla-opensource commented 2 months ago

Hi @semor-joe , We were able to successfully import the holidays into our local and development servers. Can you make sure that you are using the latest code ?

semor-joe commented 2 months ago

Hi, I have started the application with your docker compose file and this issue will appear. I tried to write my own Dockerfile and now it is working. Thanks!

One more question, how can I backup the data? I am not familiar with that.

Thank you!

horilla-opensource commented 2 months ago

Hi @semor-joe , Can you please share what was the issue that caused the issue and also the solution for future references ?

For the backup case, we are developing a backup system for postgresql database to google drive. It's currently completed and now under testing. We'll be able to release it in coming days. We'll update you once it's been added.

With Regards, Team Horilla

semor-joe commented 2 months ago

I am not sure what was the issue. I assume it can be the problem within the docker-compose.yaml. With docker compose up -d the server will start but when I try to import the holidays, it appreas the error that I have shared here, then I created own Dockerfile:

# set the working direction
WORKDIR /app

RUN apt-get update -y --fix-missing
RUN pip install Django
# Copy requirements
COPY . .
# install depandencies from requirements.txt
RUN pip install -r /app/requirements.txt
RUN python manage.py makemigrations
RUN python manage.py migrate
RUN python manage.py collectstatic --noinput
RUN python manage.py createhorillauser --first_name admin --last_name admin --username admin --password admin --email admin@example.com --phone 1234567890
EXPOSE 8000
CMD python manage.py runserver 0.0.0.0:8000

And it is working now.

Also, starting with docker-compose.yaml does not provid any test data and when I start the aplication with pyhton or my own dockerfile, the test data will shown. So maybe it is setting of db in docker-compose.yaml not correct.

centaurusgod commented 1 month ago

I have downloaded .ics file from google and converted it into xlsx. And I am still getting the error. Can you please verify if this is a correct format that horilla accepts. It also downloads an error file after uploading the excel file. image image

horilla-opensource commented 1 month ago

Hi @centaurusgod , Please check with the import template headers. It should be start date and end date (not start time and end time).

With Regards, Team Horilla

horilla-opensource commented 1 month ago

Hi @centaurusgod @semor-joe , We are closing this issue due to inactivity. It seems that there hasn't been any recent activity or discussion, and we believe it may have been resolved or is no longer relevant. If you feel this issue is still important and should be addressed, please feel free to reopen it or create a new issue with updated details.

With Regards, Team Horilla