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
[bug] Fix API prefix add error #132 #136
[bug] Fix API prefix add error #132 #136
Conversation
15cf044
to
54525b5
Compare
Pull Request Test Coverage Report for Build 527
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the implementation of this view is really weird.
All that code executed in the if I think shouldn't be done there but handled in the serializer, and then serializer.save() should be called.
However, I'm not sure if that's the cause of the issue.
Can you tell me how to replicate the issue so I'll try to do so?
To reproduce the issue, just make a request to batchview API for generating users, example:
Without |
fc141ce
to
96da8a7
Compare
I have not found the reason for the original problem. To reproduce the same please, please see the comment above and create that request in the master branch! 😄 However, I have moved the radius batch creation to serializer where I create the radiusbatch which takes care of the |
96da8a7
to
c44a9ef
Compare
c44a9ef
to
854e5f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking better, so you weren't able to reproduce this bug in tests at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to flag as more work needed.
5113aa8
to
9222b4c
Compare
5ffdfff
to
dcbd2d7
Compare
1222ab7
to
8a8c0b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this should work, contains 2 commits, one of them has a seperate PR open here #144
openwisp_radius/api/serializers.py
Outdated
batch_data = data.copy() | ||
batch_data.pop('number_of_users', None) | ||
slug = batch_data.pop('organization_slug') | ||
batch_data.update(organization=Organization.objects.get(slug=slug)) | ||
instance = self.instance or self.Meta.model(**batch_data) | ||
instance.full_clean() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While debugging on the web API interface, I noticed another issue that I didn't think about before, so I have added a model check with some modification. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried again to create a radius batch from the form of the web UI.
POST data:
csrfmiddlewaretoken: pHv9NP6y4jR3cXnFJrGCfs6o0kEy8hoeZlW68Q5gx4fTcrCJQH8Q9SZTVt9Ac9Xl
organization_slug: staging
prefix: gsoc20-
csvfile: (binary)
number_of_users: 2
strategy: prefix
name: gsoc20
expiration_date:
Result:
Traceback (most recent call last):
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/rest_framework/views.py", line 505, in dispatch
response = self.handle_exception(exc)
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/rest_framework/views.py", line 465, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
raise exc
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/rest_framework/views.py", line 502, in dispatch
response = handler(request, *args, **kwargs)
File "/home/nemesis/Code/openwisp/openwisp-radius/openwisp_radius/api/views.py", line 357, in post
if serializer.is_valid():
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/rest_framework/serializers.py", line 234, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/rest_framework/serializers.py", line 436, in run_validation
value = self.validate(value)
File "/home/nemesis/Code/openwisp/openwisp-radius/openwisp_radius/api/serializers.py", line 149, in validate
batch_data.update(organization=Organization.objects.get(slug=slug))
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/nemesis/.virtualenvs/openwisp2/lib/python3.7/site-packages/django/db/models/query.py", line 417, in get
self.model._meta.object_name
Exception Type: DoesNotExist at /api/v1/radiusbatch/
Exception Value: Organization matching query does not exist.
37c87c2
to
744dd61
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Git log:
744dd61 - (HEAD -> atb00ker-issues/132-batch-add-user) [bug] Fix API prefix add error #132 (5 hours ago) <Ajay Tripathi>
211c30c - [change] Converted cron management commands to celery beat periodic tasks #117 (8 hours ago) <Ajay Tripathi>
7c42457 - (origin/master, origin/HEAD) [fix] Fixed sample-app migration problems (8 hours ago) <Ajay Tripathi>
07ae291 - (master) [minor] Improves sample-radius migrations #143 (25 hours ago) <Ajay Tripathi>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With ipdb:
-> batch_data.update(organization=Organization.objects.get(slug=org_slug))
(Pdb) org_slug
<Organization: FVGwifi demo>
org_slug
is an organization instance instead of a string.
Yes! Thank you for the information, I am able to reproduce it now.. on it! 😄 |
744dd61
to
082a2d8
Compare
Fixed the problem and made changes in tests to ensure such error is captured by automated tests. |
0f83b43
to
27b039d
Compare
27b039d
to
b21f16f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Closes #132