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

Handle Invalid EntityID reference #2703

Open
ukanga opened this issue Sep 16, 2024 · 0 comments
Open

Handle Invalid EntityID reference #2703

ukanga opened this issue Sep 16, 2024 · 0 comments
Labels

Comments

@ukanga
Copy link
Member

ukanga commented Sep 16, 2024

Environmental Information

  • Onadata version:

Problem description

On Entity forms, a non UUID field may be pulled, which could result in the invalid UUID exception. It may be necessary to validate the correct field is being used.

{address space usage: 840015872 bytes/801MB} {rss usage: 165089280 bytes/157MB} [pid: 159|app: 0|req: 619/949] 10.15.39.41 () {78 vars in 2695 bytes} [Mon Sep 16 16:57:
01 2024] POST /enketo/21159/submission => generated 3918 bytes in 856 msecs (HTTP/1.1 500) 6 headers in 3875 bytes (1 switches on core 0)
ERROR 2024-09-16 16:57:03,277 log 159 281473254632608 Internal Server Error: /enketo/<form id>/submission
Traceback (most recent call last):
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 2688, in to_python
    return uuid.UUID(**{input_form: value})
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/uuid.py", line 177, in __init__
    raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadecimal UUID string

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/sentry_sdk/integrations/django/views.py", line 84, in sentry_wrapped_callback
    return callback(request, *args, **kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/viewsets.py", line 124, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/srv/onadata/./onadata/apps/api/viewsets/xform_submission_viewset.py", line 153, in handle_exception
    return super().handle_exception(exc)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/srv/onadata/./onadata/apps/api/viewsets/xform_submission_viewset.py", line 125, in create
    return super().create(request, *args, **kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/mixins.py", line 19, in create
    self.perform_create(serializer)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/mixins.py", line 24, in perform_create
    serializer.save()
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/serializers.py", line 208, in save
    self.instance = self.create(validated_data)
  File "/srv/onadata/./onadata/libs/utils/analytics.py", line 178, in decorator
    return_value = func(obj, *args)
  File "/srv/onadata/./onadata/libs/serializers/data_serializer.py", line 325, in create
    error, instance = safe_create_instance(
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/multidb/pinning.py", line 41, in decorator
    return func(*args, **kw)
  File "/srv/onadata/./onadata/libs/utils/logger_tools.py", line 645, in safe_create_instance
    instance = create_instance(
  File "/srv/onadata/./onadata/libs/utils/logger_tools.py", line 596, in create_instance
    instance = save_submission(
  File "/srv/onadata/./onadata/libs/utils/logger_tools.py", line 490, in save_submission
    instance = _get_instance(
  File "/srv/onadata/./onadata/libs/utils/logger_tools.py", line 202, in _get_instance
    instance = Instance.objects.create(
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/query.py", line 658, in create
    obj.save(force_insert=True, using=self.db)
  File "/srv/onadata/./onadata/apps/logger/models/instance.py", line 796, in save
    super().save(*args, **kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/base.py", line 814, in save
    self.save_base(
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/base.py", line 892, in save_base
    post_save.send(
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 176, in send
    return [
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 177, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/sentry_sdk/integrations/django/signals_handlers.py", line 76, in wrapper
    return receiver(*args, **kwargs)
  File "/srv/onadata/./onadata/apps/logger/signals.py", line 46, in create_or_update_entity
    create_or_update_entity_from_instance(instance)
  File "/srv/onadata/./onadata/libs/utils/logger_tools.py", line 1147, in create_or_update_entity_from_instance
    exists = Entity.objects.filter(uuid=entity_uuid).exists()
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/query.py", line 1436, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/query.py", line 1454, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/query.py", line 1461, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1546, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1577, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1492, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1319, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/lookups.py", line 27, in __init__
    self.rhs = self.get_prep_lookup()
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/lookups.py", line 341, in get_prep_lookup
    return super().get_prep_lookup()
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/lookups.py", line 85, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 2672, in get_prep_value
    return self.to_python(value)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 2690, in to_python
    raise exceptions.ValidationError(
django.core.exceptions.ValidationError: ['“254734566766” is not a valid UUID.']

Expected behavior

Steps to reproduce the behavior

Additional Information

Logs, related issues, weird / out of place occurrences, local settings, possible approach to solving this...

@ukanga ukanga added the Error label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant