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

Object of type ObjectId is not JSON serializable #297

Open
481460Prasanna opened this issue Aug 21, 2023 · 2 comments
Open

Object of type ObjectId is not JSON serializable #297

481460Prasanna opened this issue Aug 21, 2023 · 2 comments

Comments

@481460Prasanna
Copy link

481460Prasanna commented Aug 21, 2023

Hi,

While using the django restframework generics.ListCreateAPIView, I am getting below issue for a simple mongodb document, I am getting below error.

TypeError: Object of type ObjectId is not JSON serializable

I am using below versions,
django-rest-framework-mongoengine 3.4.1
djangorestframework 3.14.0
Django 3.2.6

Please help and guide further.

Here is the exception stacktrace for reference.

Traceback (most recent call last):
File "C:\venvs\ttap\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\venvs\ttap\lib\site-packages\django\core\handlers\base.py", line 204, in get_response
response = response.render()
File "C:\venvs\ttap\lib\site-packages\django\template\response.py", line 105, in render
self.content = self.rendered_content
File "C:\venvs\ttap\lib\site-packages\rest_framework\response.py", line 70, in rendered_content
ret = renderer.render(self.data, accepted_media_type, context)
File "C:\venvs\ttap\lib\site-packages\rest_framework\renderers.py", line 99, in render
ret = json.dumps(
File "C:\venvs\ttap\lib\site-packages\rest_framework\utils\json.py", line 25, in dumps
return json.dumps(*args, **kwargs)
File "C:\tz_apps\mnc\lib\json_init
.py", line 234, in dumps
return cls(
File "C:\tz_apps\mnc\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\tz_apps\mnc\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\venvs\ttap\lib\site-packages\rest_framework\utils\encoders.py", line 67, in default
return super().default(obj)
File "C:\tz_apps\mnc\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type ObjectId is not JSON serializable

@IATF
Copy link

IATF commented Aug 21, 2023 via email

@481460Prasanna
Copy link
Author

For additional details, This issue happens intermittently, and requires the machine restart to solve.

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