From 5b42e6a076d0deffd54da0a4c805052f2a525f81 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Wed, 29 Oct 2025 09:51:55 +0330 Subject: [PATCH] fix bug of validate org --- .../api/v1/serializers/serializer.py | 3 +- logs/django_requests.log | 131 ++++++++++++++++++ 2 files changed, 132 insertions(+), 2 deletions(-) diff --git a/apps/authentication/api/v1/serializers/serializer.py b/apps/authentication/api/v1/serializers/serializer.py index 77b409a..d77467a 100644 --- a/apps/authentication/api/v1/serializers/serializer.py +++ b/apps/authentication/api/v1/serializers/serializer.py @@ -231,8 +231,7 @@ class OrganizationSerializer(serializers.ModelSerializer): @ validate national_unique_code to be unique @ validate to organization type field """ - data = self.context.get('request') - national_unique_id = (data.get('organization'))['national_unique_id'] + national_unique_id = attrs['national_unique_id'] if not self.instance: if self.Meta.model.objects.filter(national_unique_id=national_unique_id).exists(): diff --git a/logs/django_requests.log b/logs/django_requests.log index 3eaa434..dd2d457 100644 --- a/logs/django_requests.log +++ b/logs/django_requests.log @@ -330,3 +330,134 @@ django.core.exceptions.FieldError: Unsupported lookup 'name' for ForeignKey or j [2025-10-28 16:04:07,708] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader [2025-10-28 16:46:52,938] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading. [2025-10-28 16:46:57,388] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-10-29 09:48:14,284] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-10-29 09:48:24,422] INFO django.server | IP: - | Path: - | "POST /captcha/ HTTP/1.1" 200 730 +[2025-10-29 09:49:05,642] INFO django.server | IP: - | Path: - | "POST /auth/api/v1/login/ HTTP/1.1" 200 681 +[2025-10-29 09:49:31,512] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/organization/ | Not Acceptable: /auth/api/v1/organization/ +[2025-10-29 09:49:31,513] WARNING django.server | IP: - | Path: - | "POST /auth/api/v1/organization/ HTTP/1.1" 406 70 +[2025-10-29 09:49:45,399] ERROR django.request | IP: 127.0.0.1 | Path: /auth/api/v1/organization/ | Internal Server Error: /auth/api/v1/organization/ +Traceback (most recent call last): + File "D:\Software\env\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\views\decorators\csrf.py", line 65, in _view_wrapper + return view_func(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\viewsets.py", line 125, in view + return self.dispatch(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 515, in dispatch + response = self.handle_exception(exc) + ^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 472, in handle_exception + response = exception_handler(exc, context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 512, in dispatch + response = handler(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\python-3.12.0\Lib\contextlib.py", line 81, in inner + return func(*args, **kwds) + ^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py", line 265, in create + if serializer.is_valid(): + ^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 225, in is_valid + self._validated_data = self.run_validation(self.initial_data) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 447, in run_validation + value = self.validate(value) + ^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py", line 235, in validate + national_unique_id = (data.get('organization'))['national_unique_id'] + ^^^^^^^^ +AttributeError: 'NoneType' object has no attribute 'get' +[2025-10-29 09:49:45,446] ERROR django.server | IP: - | Path: - | "POST /auth/api/v1/organization/ HTTP/1.1" 500 130407 +[2025-10-29 09:50:27,616] ERROR django.request | IP: 127.0.0.1 | Path: /auth/api/v1/organization/ | Internal Server Error: /auth/api/v1/organization/ +Traceback (most recent call last): + File "D:\Software\env\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\views\decorators\csrf.py", line 65, in _view_wrapper + return view_func(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\viewsets.py", line 125, in view + return self.dispatch(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 515, in dispatch + response = self.handle_exception(exc) + ^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 472, in handle_exception + response = exception_handler(exc, context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 512, in dispatch + response = handler(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\python-3.12.0\Lib\contextlib.py", line 81, in inner + return func(*args, **kwds) + ^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py", line 265, in create + if serializer.is_valid(): + ^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 225, in is_valid + self._validated_data = self.run_validation(self.initial_data) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 447, in run_validation + value = self.validate(value) + ^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py", line 235, in validate + national_unique_id = (data.get('organization'))['national_unique_id'] + ^^^^^^^^ +AttributeError: 'NoneType' object has no attribute 'get' +[2025-10-29 09:50:27,672] ERROR django.server | IP: - | Path: - | "POST /auth/api/v1/organization/ HTTP/1.1" 500 130802 +[2025-10-29 09:50:48,041] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading. +[2025-10-29 09:50:50,059] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-10-29 09:50:55,995] ERROR django.request | IP: 127.0.0.1 | Path: /auth/api/v1/organization/ | Internal Server Error: /auth/api/v1/organization/ +Traceback (most recent call last): + File "D:\Software\env\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\django\views\decorators\csrf.py", line 65, in _view_wrapper + return view_func(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\viewsets.py", line 125, in view + return self.dispatch(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 515, in dispatch + response = self.handle_exception(exc) + ^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 472, in handle_exception + response = exception_handler(exc, context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\views.py", line 512, in dispatch + response = handler(request, *args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\python-3.12.0\Lib\contextlib.py", line 81, in inner + return func(*args, **kwds) + ^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py", line 265, in create + if serializer.is_valid(): + ^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 225, in is_valid + self._validated_data = self.run_validation(self.initial_data) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "D:\Software\env\Lib\site-packages\rest_framework\serializers.py", line 447, in run_validation + value = self.validate(value) + ^^^^^^^^^^^^^^^^^^^^ + File "D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py", line 235, in validate + national_unique_id = data.get('national_unique_id') + ^^^^^^^^ +AttributeError: 'NoneType' object has no attribute 'get' +[2025-10-29 09:50:56,057] ERROR django.server | IP: - | Path: - | "POST /auth/api/v1/organization/ HTTP/1.1" 500 130744 +[2025-10-29 09:51:29,946] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading. +[2025-10-29 09:51:33,813] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader +[2025-10-29 09:51:47,218] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/organization/ | Forbidden: /auth/api/v1/organization/ +[2025-10-29 09:51:47,219] WARNING django.server | IP: - | Path: - | "POST /auth/api/v1/organization/ HTTP/1.1" 403 86