jazzband / django-user-sessions

Extend Django sessions with a foreign key back to the user, allowing enumerating all user's sessions.
https://pypi.python.org/pypi/django-user-sessions
MIT License
618 stars 129 forks source link

DataError: ERROR: value too long for type character(200) #80

Open habryk93 opened 6 years ago

habryk93 commented 6 years ago

Error when send to long user-agent header

Expected Behavior

Status 200

Current Behavior

File "/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response response = middleware_method(request, response)

File "/python2.7/site-packages/user_sessions/middleware.py", line 46, in process_response request.session.save()

File "/python2.7/site-packages/user_sessions/backends/db.py", line 78, in save obj.save(force_insert=must_create, using=using)

DataError: ERROR: value too long for type character(200)

Possible Solution

Should change Session model field user_agent from CharField to TextField user_agent = models.CharField(null=True, blank=True, max_length=200) to user_agent = models.TextField(null=True, blank=True) or cropp user_agent field before save to db(but it can delete necessary information) or add max_length for exaple with 500 to TextField, but its not limit field in DB, only in django

Steps to Reproduce (for bugs)

  1. Add link to my page on facebook
  2. Go to link
  3. Facebook add some info to user_agent info
  4. Page return 500 (DataError: ERROR: value too long for type character)

Context

Your Environment

Bouke commented 6 years ago

What database backend are you using?

habryk93 commented 6 years ago

Postgres, but it is not problem with DB, you restrict your user_agent field to 200 symbols. https://stackoverflow.com/questions/654921/how-big-can-a-user-agent-string-get