miratcan / qhonuskan-votes

Simple reddit like voting system without usage off GenericForeignKeys. Built for linkfloyd project.
Other
30 stars 11 forks source link

When voted arrow clicked again it raises error. #31

Open miratcan opened 4 years ago

miratcan commented 4 years ago
[21/Jul/2020 02:21:16] "POST /votes/vote/ HTTP/1.1" 200 27
Internal Server Error: /votes/vote/
Traceback (most recent call last):
  File "/Users/mirat/.pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/Users/mirat/.pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/mirat/.pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/mirat/.pyenv/versions/3.7.4/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/mirat/Repos/qhonuskan-votes/demo/qhonuskan_votes/views.py", line 48, in view
    return func(request, model, object_id, value)
  File "/Users/mirat/Repos/qhonuskan-votes/demo/qhonuskan_votes/views.py", line 69, in vote
    vote_instance.delete()
  File "/Users/mirat/Repos/qhonuskan-votes/demo/qhonuskan_votes/models.py", line 131, in delete
    vote_changed.send(sender=self)
  File "/Users/mirat/.pyenv/versions/3.7.4/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 170, in send
    if not self.receivers or self.sender_receivers_cache.get(sender) is NO_RECEIVERS:
  File "/Users/mirat/.pyenv/versions/3.7.4/lib/python3.7/site-packages/django/db/models/base.py", line 536, in __hash__
    raise TypeError("Model instances without primary key value are unhashable")
TypeError: Model instances without primary key value are unhashable
ghost commented 2 years ago

Yeah having this issue, trying to assess what the solution is.

ghost commented 2 years ago

The issue has to do with the delete() method calling super.

        def delete(self, *args, **kwargs):
            vote_changed.send(sender=self)
            super(Vote, self).delete(*args, **kwargs)

Changing the order of the signal seemed to work for me. That or removing the delete method entirely. Something about the primary key being none when it tries to hash. Would need other people to test and verify to find the proper solution.

miratcan commented 2 years ago

Hi, I'm not maintaining the code ATM. If you send pull request I can accept.

JJ Zolper @.***>, 28 Şub 2022 Pzt, 05:23 tarihinde şunu yazdı:

The issue has to do with the delete() method calling super.

    def delete(self, *args, **kwargs):
        vote_changed.send(sender=self)
        super(Vote, self).delete(*args, **kwargs)

Changing the order of the signal seemed to work for me. That or removing the delete method entirely. Something about the primary key being none when it tries to hash. Would need other people to test and verify to find the proper solution.

— Reply to this email directly, view it on GitHub https://github.com/miratcan/qhonuskan-votes/issues/31#issuecomment-1053807538, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABCNKFZK7VCUT4WAHTU6GLU5LMDTANCNFSM4PDJSNNA . You are receiving this because you authored the thread.Message ID: @.***>