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

Database error with signed browser cookie-based sessions #81

Open
peterbispham opened this issue Aug 30, 2019 · 4 comments
Open

Database error with signed browser cookie-based sessions #81

peterbispham opened this issue Aug 30, 2019 · 4 comments
Assignees
Labels

Comments

@peterbispham
Copy link

peterbispham commented Aug 30, 2019

Hi there

First of all thanks for a great utility. Thought I'd flag an issue I noticed in case it helps.

When using signed browser cookies, the session_key parameter can become rather large and on my postgres database I'm getting these errors:

<class 'django.db.utils.DataError'> value too long for type character varying(40), referer: https://....

Raised in a call such as the following:
hit_count = HitCount.objects.get_for_object(article) hit_count_response = HitCountMixin.hit_count(request, hit_count) . <-- this call

This is when using session middleware:
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'
When reverting to database cookies which appear to be 32 chars in length then all is well.

SESSION_ENGINE = 'django.contrib.sessions.backends.db'
Might not be something you plan to support but thought I'd flag it in case anyone else is getting the same issue. The side-effect is that hits are not being stored in the session so every time a page is loaded it contributes a hit to the total.

Django 2.0.13
Python 3.7.4

Thanks :)

@bashu bashu added the bug label Oct 16, 2019
@bashu bashu self-assigned this Oct 16, 2019
@siovene
Copy link

siovene commented Apr 7, 2021

Hi @peterbispham, I have the same problem. Did you find a workaround? Thanks!

@peterbispham
Copy link
Author

@siovene only the workaround I mentioned above, i.e. using database cookies. I didn't find any other solution. I'm not using hitcount at the moment so can't be any more help than that, sorry.

@siovene
Copy link

siovene commented Apr 7, 2021

@peterbispham I'm afraid changing the session engine is not an option for me, for performance reasons and also because I don't want to log out tens of thousands of users with this update. Do you know how large the session key can get with the signed cookie engine? I will fork django-hitcount to make the session property accept larger values.

@peterbispham
Copy link
Author

Not sure if it's a fixed size but the max cookie size in a browser is 4096 bytes I think so if you could handle that then you should be fine. Good luck :)

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

No branches or pull requests

3 participants