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

When choose 'By Question" or "By Category" ans using "date" type, Object of type 'date' is not JSON serializable #105

Open
turbok2 opened this issue Nov 3, 2020 · 15 comments

Comments

@turbok2
Copy link

turbok2 commented Nov 3, 2020

When choose 'By Question" or "By Category" ans using "date" type,
there is an error like below:
When I choice date at first page and click 'I'm done'
In case I made questions using 'By category' and more then 2 category.
It's okay. when i use "All in one page"
or when I made questions with 1 category or put a question (date) at last page.
I use new version.( I cloned 2021-03-15)

http://127.0.0.1:8000/survey/12/
2.2.2
TypeError
Object of type 'date' is not JSON serializable
/home/turbo/anaconda3/lib/python3.6/json/encoder.py in default, line 180
/home/turbo/django/venv/bin/python
3.6.10
['/home/turbo/django/django-survey', '/home/turbo/study/models/research', '/home/turbo/study/models/research/slim', '/home/turbo/study/now/Mask_RCNN/cocoapi/PythonAPI', '/home/turbo/django/venv/lib/python36.zip', '/home/turbo/django/venv/lib/python3.6', '/home/turbo/django/venv/lib/python3.6/lib-dynload', '/home/turbo/anaconda3/lib/python3.6', '/home/turbo/django/venv/lib/python3.6/site-packages']
Mon, 15 Mar 2021 11:55:09 +0900

traceback
Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/survey/12/

Django Version: 2.2.2
Python Version: 3.6.10
Installed Applications:
('django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'survey',
'bootstrapform',
'rosetta',
'debug_toolbar')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')

Traceback:

File "/home/turbo/django/venv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)

File "/home/turbo/django/venv/lib/python3.6/site-packages/django/utils/deprecation.py" in call
96. response = self.process_response(request, response)

File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/middleware.py" in process_response
58. request.session.save()

File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py" in save
83. obj = self.create_model_instance(data)

File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py" in create_model_instance
70. session_data=self.encode(data),

File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py" in encode
95. serialized = self.serializer().dumps(session_dict)

File "/home/turbo/django/venv/lib/python3.6/site-packages/django/core/signing.py" in dumps
87. return json.dumps(obj, separators=(',', ':')).encode('latin-1')

File "/home/turbo/anaconda3/lib/python3.6/json/init.py" in dumps
238. **kw).encode(obj)

File "/home/turbo/anaconda3/lib/python3.6/json/encoder.py" in encode
199. chunks = self.iterencode(o, _one_shot=True)

File "/home/turbo/anaconda3/lib/python3.6/json/encoder.py" in iterencode
257. return _iterencode(o, 0)

File "/home/turbo/anaconda3/lib/python3.6/json/encoder.py" in default
180. o.class.name)

Exception Type: TypeError at /survey/12/
Exception Value: Object of type 'date' is not JSON serializable

@Pierre-Sassoulas
Copy link
Owner

Hello, thank you for the bug report, would you have the full stacktrace of the error please ?

@turbok2
Copy link
Author

turbok2 commented Nov 5, 2020

I don't know full stacktrace. so I copy some infomation in the trackback section.
if you want login id, passwd, I can offer. let me know.

Environment:

Request Method: POST
Request URL: http://110.8.206.17:8000/survey/12/

Django Version: 2.2.2
Python Version: 3.6.10
Installed Applications:
('django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'survey',
 'bootstrapform',
 'rosetta',
 'debug_toolbar')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware')

Traceback:

File "/home/turbo/django/venv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/utils/deprecation.py" in __call__
  96.             response = self.process_response(request, response)
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/middleware.py" in process_response
  58.                             request.session.save()
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py" in save
  83.         obj = self.create_model_instance(data)
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py" in create_model_instance
  70.             session_data=self.encode(data),
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py" in encode
  95.         serialized = self.serializer().dumps(session_dict)
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/core/signing.py" in dumps
  87.         return json.dumps(obj, separators=(',', ':')).encode('latin-1')
File "/home/turbo/anaconda3/lib/python3.6/json/__init__.py" in dumps
  238.         **kw).encode(obj)
File "/home/turbo/anaconda3/lib/python3.6/json/encoder.py" in encode
  199.         chunks = self.iterencode(o, _one_shot=True)
File "/home/turbo/anaconda3/lib/python3.6/json/encoder.py" in iterencode
  257.         return _iterencode(o, 0)
File "/home/turbo/anaconda3/lib/python3.6/json/encoder.py" in default
  180.                         o.__class__.__name__)
Exception Type: TypeError at /survey/12/
Exception Value: Object of type 'date' is not JSON serializable

@Pierre-Sassoulas
Copy link
Owner

Thanks, if giving your passwords hashes is not a problem would appreciate to have the dump of the database to reproduce the problem. Can you upload issue_105.json after launching python manage.py dumpdata > issue_105.json, please ?

@turbok2
Copy link
Author

turbok2 commented Nov 9, 2020

Ok, I can give you my info. Let me know your contact email address. I'll reply.
and I attach issue_105.json file.
issue_105.json.zip

@turbok2 turbok2 closed this as completed Nov 10, 2020
@turbok2
Copy link
Author

turbok2 commented Nov 10, 2020

open again. sorry.

@turbok2 turbok2 reopened this Nov 10, 2020
@Pierre-Sassoulas
Copy link
Owner

Don't worry I don't need your password, I can create another super user :)

@turbok2
Copy link
Author

turbok2 commented Nov 10, 2020

You can use my site now.
http://110.8.206.17:8000/survey/12/

when you fill 'foundation date 설립일' and press "I'm done". you can see that error msg.

@Pierre-Sassoulas
Copy link
Owner

Hi again, I tried to load the json dump but I had a problem with a new field called "ext" django.core.exceptions.FieldDoesNotExist: Question has no field named 'ext', after removing all the "ext" I had another problem: django.core.exceptions.ValidationError: ["Impossible answer '20-이상' should be in ['20% 이상|\\r\\n10% 이상~20% 미만|\\r\\n3% 이상~10% 미만|\\r\\n3% 미만|\\r\\n해당없음'] "]. Look like the were some modification to the database schema and I cannot reproduce the problem.

@turbok2
Copy link
Author

turbok2 commented Nov 14, 2020

Sorry, I modified some code. I also removed that code. ( ext) ^^;
next, It's Korean. So I change it to English. So you can use it now. and I use | as a CHOICES_SEPARATOR instead of , .
test1 http://110.8.206.17:8000/survey/15/
test2 http://110.8.206.17:8000/survey/16/

test1 is no problem. it has date field in last category.

but, test2 has some problem.
because that first category has date field.


Environment:

Request Method: POST
Request URL: http://localhost:8000/survey/16/

Django Version: 2.2.2
Python Version: 3.6.10
Installed Applications:
('django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'survey',
 'bootstrapform',
 'rosetta',
 'debug_toolbar')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware')

Traceback:

File "/home/turbo/django/venv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/utils/deprecation.py" in __call__
  96.             response = self.process_response(request, response)
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/middleware.py" in process_response
  58.                             request.session.save()
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py" in save
  83.         obj = self.create_model_instance(data)
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py" in create_model_instance
  70.             session_data=self.encode(data),
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py" in encode
  95.         serialized = self.serializer().dumps(session_dict)
File "/home/turbo/django/venv/lib/python3.6/site-packages/django/core/signing.py" in dumps
  87.         return json.dumps(obj, separators=(',', ':')).encode('latin-1')
File "/home/turbo/anaconda3/lib/python3.6/json/__init__.py" in dumps
  238.         **kw).encode(obj)
File "/home/turbo/anaconda3/lib/python3.6/json/encoder.py" in encode
  199.         chunks = self.iterencode(o, _one_shot=True)
File "/home/turbo/anaconda3/lib/python3.6/json/encoder.py" in iterencode
  257.         return _iterencode(o, 0)
File "/home/turbo/anaconda3/lib/python3.6/json/encoder.py" in default
  180.                         o.__class__.__name__)

Exception Type: TypeError at /survey/16/
Exception Value: Object of type 'date' is not JSON serializable

@a-wip0
Copy link

a-wip0 commented Nov 19, 2020

@turbok2 sorry for out of topic question, how did you remove "Answer This Part" text? its always appear in my survey even if there is only i category or less used

@turbok2
Copy link
Author

turbok2 commented Nov 22, 2020

@turbok2 sorry for out of topic question, how did you remove "Answer This Part" text? its always appear in my survey even if there is only i category or less used

If you change some code in html file, you can control.
in survey/templates/survey/survey.html
line 48, remove 'collapse'
line 39-46 remove all lines.

@malep2007
Copy link

Seems like when you try to change the way the questions are displayed from the default, "All questions in one page" to any other display settings of the survey, you get this error of the Date not being JSON serializable when you try to navigate to the next category/ question. My stack trace is as below.

Traceback (most recent call last):
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/utils/deprecation.py", line 116, in __call__
    response = self.process_response(request, response)
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/contrib/sessions/middleware.py", line 63, in process_response
    request.session.save()
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/contrib/sessions/backends/db.py", line 83, in save
    obj = self.create_model_instance(data)
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/contrib/sessions/backends/db.py", line 70, in create_model_instance
    session_data=self.encode(data),
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/contrib/sessions/backends/base.py", line 114, in encode
    return signing.dumps(
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/core/signing.py", line 110, in dumps
    data = serializer().dumps(obj)
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/core/signing.py", line 87, in dumps
    return json.dumps(obj, separators=(',', ':')).encode('latin-1')
  File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type date is not JSON serializable

@turbok2
Copy link
Author

turbok2 commented Mar 15, 2021

Seems like when you try to change the way the questions are displayed from the default, "All questions in one page" to any other display settings of the survey, you get this error of the Date not being JSON serializable when you try to navigate to the next category/ question. My stack trace is as below.

Traceback (most recent call last):
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/utils/deprecation.py", line 116, in __call__
    response = self.process_response(request, response)
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/contrib/sessions/middleware.py", line 63, in process_response
    request.session.save()
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/contrib/sessions/backends/db.py", line 83, in save
    obj = self.create_model_instance(data)
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/contrib/sessions/backends/db.py", line 70, in create_model_instance
    session_data=self.encode(data),
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/contrib/sessions/backends/base.py", line 114, in encode
    return signing.dumps(
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/core/signing.py", line 110, in dumps
    data = serializer().dumps(obj)
  File "/Users/ephraimmalinga/Documents/projects/venv/survey-env/lib/python3.9/site-packages/django/core/signing.py", line 87, in dumps
    return json.dumps(obj, separators=(',', ':')).encode('latin-1')
  File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/Cellar/[email protected]/3.9.1_8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type date is not JSON serializable

Right!! in other options except "All questions in one page", I got an error.
I hope to use "by category" .
If you find solution, let me know please.

@turbok2 turbok2 changed the title Object of type 'date' is not JSON serializable When choose 'By Question" or "By Category" ans using "date" type, Object of type 'date' is not JSON serializable Mar 15, 2021
@HenryMehta
Copy link

Has there been any progress on this? I have the same issue

@Pierre-Sassoulas
Copy link
Owner

I'm not developing anymore on this project, but I review and merge contributions :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants