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

Support non-alphanumeric version IDs in form versions endpoint #2716

Open
ciremusyoka opened this issue Oct 3, 2024 · 0 comments
Open

Support non-alphanumeric version IDs in form versions endpoint #2716

ciremusyoka opened this issue Oct 3, 2024 · 0 comments
Labels

Comments

@ciremusyoka
Copy link
Contributor

Problem description

The current implementation of the /api/v1/forms/<formid>/versions endpoint only supports alphabetic and digit characters in the version_id field. This causes errors when users manually set version IDs that include non-alphanumeric characters, such as dots (.) or other special characters.

Error thrown.

ERROR 2024-10-03 06:21:40,912 log 322 137061597878208 Internal Server Error: /api/v1/forms/1/versions
Traceback (most recent call last):
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/relations.py", line 396, in to_representation
    url = self.get_url(value, self.view_name, request, format)
  File "/srv/onadata/./onadata/libs/serializers/xform_serializer.py", line 168, in get_url
    return reverse(view_name, kwargs=kwargs, request=request, format=fmt)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/reverse.py", line 47, in reverse
    url = _reverse(viewname, args, kwargs, request, format, **extra)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/rest_framework/reverse.py", line 60, in _reverse
    url = django_reverse(viewname, args=args, kwargs=kwargs, **extra)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/urls/base.py", line 88, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "/home/appuser/.pyenv/versions/3.10.14/lib/python3.10/site-packages/django/urls/resolvers.py", line 828, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'form-version-detail' with keyword arguments '{'pk': 1, 'version_id': '1.1'}' not found. 2 pattern(s) tried: ['api/v1/forms/(?P<pk>[^/.]+)/versions/(?P<version_id>[^/.]+)\\.(?P<format>[a-z0-9]+)/?$', 'api/v1/forms/(?P<pk>[^/.]+)/versions/(?P<version_id>[^/.]+)$']

Expected behavior

The API should accept version IDs with non-alphanumeric characters such as dots (.) and correctly resolve the version ID in the URL patterns.

Steps to reproduce the behavior

  1. Set a form version ID with a non-alphanumeric character, e.g., 1.1.
  2. Upload the form
  3. Attempt to retrieve form versions using the endpoint /api/v1/forms/<formid>/versions.
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