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

Duplicated key importing calendar bucket #580

Open
zipus opened this issue Dec 2, 2022 · 1 comment
Open

Duplicated key importing calendar bucket #580

zipus opened this issue Dec 2, 2022 · 1 comment

Comments

@zipus
Copy link
Contributor

zipus commented Dec 2, 2022

Doing a post request over api/input/calendarbucket/ with:

[
{
'calendar': 'calendar2', 'value': 1, 
'startdate': '1971-01-01 00:00:00', 
'enddate': '2100-12-31 00:00:00', 
'starttime': '7:00:00', 
'endtime': '16:00:00',
'monday': True,
'tuesday': True,
'wednesday': True,
'thursday': True,
'friday': False,
'saturday': False,
'sunday': False}, 
{
'calendar': 'calendar2', 'value': 1, 
'startdate': '1971-01-01 00:00:00', 
'enddate': '2100-12-31 00:00:00', 
'starttime': '7:00:00', 
'endtime': '13:00:00',
'monday': False,
'tuesday': False,
'wednesday': False,
'thursday': False,
'friday': True,
'saturday': False,
'sunday': False}]
[Fri Dec 02 09:38:38.468378 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] ERROR Internal Server Error: /api/input/calendarbucket/
[Fri Dec 02 09:38:38.468411 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] Traceback (most recent call last):
[Fri Dec 02 09:38:38.468416 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/lib/python3/dist-packages/freppledb/common/api/serializers.py", line 93, in create
[Fri Dec 02 09:38:38.468421 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     instance = self.Meta.model.objects.get_by_natural_key(*key)
[Fri Dec 02 09:38:38.468425 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/lib/python3/dist-packages/freppledb/input/models.py", line 132, in get_by_natural_key
[Fri Dec 02 09:38:38.468429 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     priority=priority,
[Fri Dec 02 09:38:38.468433 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/manager.py", line 85, in manager_method
[Fri Dec 02 09:38:38.468437 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return getattr(self.get_queryset(), name)(*args, **kwargs)
[Fri Dec 02 09:38:38.468441 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 437, in get
[Fri Dec 02 09:38:38.468445 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     self.model._meta.object_name
[Fri Dec 02 09:38:38.468449 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] freppledb.input.models.CalendarBucket.DoesNotExist: CalendarBucket matching query does not exist.
[Fri Dec 02 09:38:38.468453 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] 
[Fri Dec 02 09:38:38.468457 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] During handling of the above exception, another exception occurred:
[Fri Dec 02 09:38:38.468461 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] 
[Fri Dec 02 09:38:38.468465 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] Traceback (most recent call last):
[Fri Dec 02 09:38:38.468469 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 84, in _execute
[Fri Dec 02 09:38:38.468473 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return self.cursor.execute(sql, params)
[Fri Dec 02 09:38:38.468477 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "calendarbucket_calendar_id_startdate_en_7146ab31_uniq"
[Fri Dec 02 09:38:38.468490 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] DETAIL:  Key (calendar_id, startdate, enddate, priority)=(calendar2, 1971-01-01 00:00:00+01, 2100-12-31 00:00:00+01, 0) already exists.
[Fri Dec 02 09:38:38.468494 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] 
[Fri Dec 02 09:38:38.468497 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] 
[Fri Dec 02 09:38:38.468500 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] The above exception was the direct cause of the following exception:
[Fri Dec 02 09:38:38.468504 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] 
[Fri Dec 02 09:38:38.468507 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] Traceback (most recent call last):
[Fri Dec 02 09:38:38.468511 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 47, in inner
[Fri Dec 02 09:38:38.468514 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     response = get_response(request)
[Fri Dec 02 09:38:38.468518 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 181, in _get_response
[Fri Dec 02 09:38:38.468522 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Fri Dec 02 09:38:38.468525 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
[Fri Dec 02 09:38:38.468529 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return view_func(*args, **kwargs)
[Fri Dec 02 09:38:38.468532 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/views/generic/base.py", line 70, in view
[Fri Dec 02 09:38:38.468536 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return self.dispatch(request, *args, **kwargs)
[Fri Dec 02 09:38:38.468540 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 509, in dispatch
[Fri Dec 02 09:38:38.468543 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     response = self.handle_exception(exc)
[Fri Dec 02 09:38:38.468547 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 469, in handle_exception
[Fri Dec 02 09:38:38.468550 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     self.raise_uncaught_exception(exc)
[Fri Dec 02 09:38:38.468554 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
[Fri Dec 02 09:38:38.468557 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     raise exc
[Fri Dec 02 09:38:38.468561 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework/views.py", line 506, in dispatch
[Fri Dec 02 09:38:38.468565 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     response = handler(request, *args, **kwargs)
[Fri Dec 02 09:38:38.468568 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework_bulk/generics.py", line 137, in post
[Fri Dec 02 09:38:38.468572 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return self.create(request, *args, **kwargs)
[Fri Dec 02 09:38:38.468575 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework_bulk/drf3/mixins.py", line 34, in create
[Fri Dec 02 09:38:38.468582 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     self.perform_bulk_create(serializer)
[Fri Dec 02 09:38:38.468585 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework_bulk/drf3/mixins.py", line 38, in perform_bulk_create
[Fri Dec 02 09:38:38.468589 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return self.perform_create(serializer)
[Fri Dec 02 09:38:38.468593 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework/mixins.py", line 24, in perform_create
[Fri Dec 02 09:38:38.468596 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     serializer.save()
[Fri Dec 02 09:38:38.468600 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 731, in save
[Fri Dec 02 09:38:38.468604 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     self.instance = self.create(validated_data)
[Fri Dec 02 09:38:38.468607 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 704, in create
[Fri Dec 02 09:38:38.468611 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     self.child.create(attrs) for attrs in validated_data
[Fri Dec 02 09:38:38.468614 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 704, in <listcomp>
[Fri Dec 02 09:38:38.468618 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     self.child.create(attrs) for attrs in validated_data
[Fri Dec 02 09:38:38.468621 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/lib/python3/dist-packages/freppledb/common/api/serializers.py", line 96, in create
[Fri Dec 02 09:38:38.468625 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return super().create(validated_data)
[Fri Dec 02 09:38:38.468629 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/rest_framework/serializers.py", line 962, in create
[Fri Dec 02 09:38:38.468632 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     instance = ModelClass._default_manager.create(**validated_data)
[Fri Dec 02 09:38:38.468636 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/manager.py", line 85, in manager_method
[Fri Dec 02 09:38:38.468640 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return getattr(self.get_queryset(), name)(*args, **kwargs)
[Fri Dec 02 09:38:38.468643 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 453, in create
[Fri Dec 02 09:38:38.468647 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     obj.save(force_insert=True, using=self.db)
[Fri Dec 02 09:38:38.468650 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/lib/python3/dist-packages/freppledb/common/models.py", line 285, in save
[Fri Dec 02 09:38:38.468654 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     super().save(*args, **kwargs)
[Fri Dec 02 09:38:38.468657 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 740, in save
[Fri Dec 02 09:38:38.468661 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     force_update=force_update, update_fields=update_fields)
[Fri Dec 02 09:38:38.468667 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 778, in save_base
[Fri Dec 02 09:38:38.468671 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     force_update, using, update_fields,
[Fri Dec 02 09:38:38.468674 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 881, in _save_table
[Fri Dec 02 09:38:38.468678 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
[Fri Dec 02 09:38:38.468682 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 921, in _do_insert
[Fri Dec 02 09:38:38.468685 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     using=using, raw=raw,
[Fri Dec 02 09:38:38.468689 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/manager.py", line 85, in manager_method
[Fri Dec 02 09:38:38.468692 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return getattr(self.get_queryset(), name)(*args, **kwargs)
[Fri Dec 02 09:38:38.468696 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py", line 1270, in _insert
[Fri Dec 02 09:38:38.468700 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return query.get_compiler(using=using).execute_sql(returning_fields)
[Fri Dec 02 09:38:38.468703 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql
[Fri Dec 02 09:38:38.468707 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     cursor.execute(sql, params)
[Fri Dec 02 09:38:38.468711 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 66, in execute
[Fri Dec 02 09:38:38.468714 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
[Fri Dec 02 09:38:38.468718 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
[Fri Dec 02 09:38:38.468722 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return executor(sql, params, many, context)
[Fri Dec 02 09:38:38.468725 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 84, in _execute
[Fri Dec 02 09:38:38.468729 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return self.cursor.execute(sql, params)
[Fri Dec 02 09:38:38.468732 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 90, in __exit__
[Fri Dec 02 09:38:38.468736 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     raise dj_exc_value.with_traceback(traceback) from exc_value
[Fri Dec 02 09:38:38.468739 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]   File "/usr/local/lib/python3.6/dist-packages/django/db/backends/utils.py", line 84, in _execute
[Fri Dec 02 09:38:38.468743 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394]     return self.cursor.execute(sql, params)
[Fri Dec 02 09:38:38.468747 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] django.db.utils.IntegrityError: duplicate key value violates unique constraint "calendarbucket_calendar_id_startdate_en_7146ab31_uniq"
[Fri Dec 02 09:38:38.468755 2022] [wsgi:error] [pid 28:tid 139839258302208] [remote 172.19.0.1:33394] DETAIL:  Key (calendar_id, startdate, enddate, priority)=(calendar2, 1971-01-01 00:00:00+01, 2100-12-31 00:00:00+01, 0) already exists.

A get over calendar to confirm that the calendar object is populated:

[
    {
        "name": "calendar2",
        "description": null,
        "category": null,
        "subcategory": null,
        "defaultvalue": "0.00000000",
        "source": "Tryton",
        "lastmodified": "2022-12-02T09:38:38.129698"
    `}`
]

When I do only one bucket it is populated on frepple correctly, when I try to do more fails.

@hichamlahlou
Copy link
Member

Try to add a priority field in your calendar bucket posts. If you have a different priority for each of your 2 records, it should pass.

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