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

Per user vote behind proxy #26

Open
Burekas opened this issue Mar 22, 2017 · 1 comment
Open

Per user vote behind proxy #26

Burekas opened this issue Mar 22, 2017 · 1 comment

Comments

@Burekas
Copy link

Burekas commented Mar 22, 2017

Hi, thanks for great application.

REMOTE_ADDR is always 127.0.0.1 and I don't need it to be unique, just per user voting.
Does application support that ?
Thank you.

Sometimes I'm getting errors like this when voting for the first time :

Traceback:

File "/opt/envs/tworoads/lib/python3.5/site-packages/updown/fields.py" in add
108. rating, created = Vote.objects.get(**kwargs), False

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/manager.py" in manager_method
85. return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/query.py" in get
385. self.model._meta.object_name

  During handling of the above exception (Vote matching query does not exist.), another exception occurred:

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)

  The above exception (duplicate key value violates unique constraint "updown_vote_content_type_id_af6fe292_uniq"

DETAIL: Key (content_type_id, object_id, key, user_id, ip_address)=(20, 117, dfa5be7e620204da91e72a33294e9798, 3, 127.0.0.1) already exists.
) was the direct cause of the following exception:

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/opt/envs/tworoads/lib/python3.5/site-packages/updown/views.py" in call
105. request, content_type.id, object_id, field_name, score)

File "/opt/envs/tworoads/lib/python3.5/site-packages/updown/views.py" in call
42. field.add(score, request.user, request.META['REMOTE_ADDR'])

File "/opt/envs/tworoads/lib/python3.5/site-packages/updown/fields.py" in add
111. rating, created = Vote.objects.create(**kwargs), True

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/manager.py" in manager_method
85. return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/query.py" in create
399. obj.save(force_insert=True, using=self.db)

File "/opt/envs/tworoads/lib/python3.5/site-packages/updown/models.py" in save
43. super(Vote, self).save(*args, **kwargs)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/base.py" in save
796. force_update=force_update, update_fields=update_fields)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/base.py" in save_base
824. updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/base.py" in _save_table
908. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/base.py" in _do_insert
947. using=using, raw=raw)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/manager.py" in manager_method
85. return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/query.py" in _insert
1045. return query.get_compiler(using=using).execute_sql(return_id)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
1054. cursor.execute(sql, params)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/utils.py" in exit
94. six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/utils/six.py" in reraise
685. raise value.with_traceback(tb)

File "/opt/envs/tworoads/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)

Exception Type: IntegrityError at ....
Exception Value: duplicate key value violates unique constraint "updown_vote_content_type_id_af6fe292_uniq"
DETAIL: Key (content_type_id, object_id, key, user_id, ip_address)=(20, 117, dfa5be7e620204da91e72a33294e9798, 3, 127.0.0.1) already exists.

@dbanck
Copy link
Contributor

dbanck commented Apr 2, 2017

Hi!

There is no way to turn off ip checking currently. 😢
A fix would be to configure your reverse proxy to set the correct ip as `REMOTE_ADDR.

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

No branches or pull requests

2 participants