Interesting. Good catch. Kind regards, Sithu
*Sent with Shift <https://tryshift.com/?utm_source=SentWithShift&utm_campaign=Sent%20with%20Shift%20Signature&utm_medium=Email%20Signature&utm_content=General%20Email%20Group>* On Wed, Apr 17, 2019 at 9:48 PM Matthew Pava <matthew.p...@iss.com> wrote: > Okay, the model I’m using specifies an __eq__ function without a > corresponding __hash__ function. I’ve opened a pull request with the owner > of that project. > > > > *From:* django-users@googlegroups.com [mailto: > django-users@googlegroups.com] *On Behalf Of *Matthew Pava > *Sent:* Wednesday, April 17, 2019 11:18 AM > *To:* django-users@googlegroups.com > *Subject:* RE: Unhashable TypeError when deleted from model, Django 2.2 > > > > Hi Sithu, > > I would still need to a way determine when a record expires. A Boolean > wouldn’t help in that regard. > > But I think this error has something to do with Django’s delete method. > The filtering aspect works just fine. > > > > *From:* django-users@googlegroups.com [mailto: > django-users@googlegroups.com] *On Behalf Of *Sithembewena L. Dube > *Sent:* Tuesday, April 16, 2019 2:49 PM > *To:* django-users@googlegroups.com > *Subject:* Re: Unhashable TypeError when deleted from model, Django 2.2 > > > > Why not use a boolean field on the model to denote expires? Then if that > field is True, delete the object? I think that would be cheaper and > cleaner, especially with lookups. > > > > Kind regards, > Sithu > > > > *Sent with Shift > <https://tryshift.com/?utm_source=SentWithShift&utm_campaign=Sent%20with%20Shift%20Signature&utm_medium=Email%20Signature&utm_content=General%20Email%20Group>* > > > > On Tue, Apr 16, 2019 at 9:29 PM Matthew Pava <matthew.p...@iss.com> wrote: > > I have a model that has a nullable field called expires. If expires is > null, then the record never expires. > > I’m performing a delete on the model for any record that has an expires > date that has passed, and I keep getting a TypeError that Model is > unhashable. Am I doing something wrong? > > > > Model.objects.filter(expires__lt=timezone.now()).delete() > > > > Here’s the traceback: > > > > Traceback (most recent call last): > > File "\django\core\handlers\exception.py", line 34, in inner > > response = get_response(request) > > File "\django\core\handlers\base.py", line 115, in _get_response > > response = self.process_exception_by_middleware(e, request) > > File "\django\core\handlers\base.py", line 113, in _get_response > > response = wrapped_callback(request, *callback_args, **callback_kwargs) > > File "\django\views\decorators\csrf.py", line 54, in wrapped_view > > return view_func(*args, **kwargs) > > File "\django\views\generic\base.py", line 71, in view > > return self.dispatch(request, *args, **kwargs) > > File "\rest_framework\views.py", line 495, in dispatch > > response = self.handle_exception(exc) > > File "\rest_framework\views.py", line 455, in handle_exception > > self.raise_uncaught_exception(exc) > > File "\rest_framework\views.py", line 492, in dispatch > > response = handler(request, *args, **kwargs) > > File "\rest_framework\decorators.py", line 55, in handler > > return func(*args, **kwargs) > > File "C:\project\general\views.py", line 88, in all_messages_for_user > > Model.objects.filter(expires__lt=timezone.now()).delete() > > File "\django\db\models\query.py", line 710, in delete > > collector.collect(del_query) > > File "\django\db\models\deletion.py", line 192, in collect > > reverse_dependency=reverse_dependency) > > File "\django\db\models\deletion.py", line 94, in add > > if obj not in instances: > > TypeError: unhashable type: 'Model' > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/f2d2e610ffe04dff85edf80be0c7ad2d%40iss2.ISS.LOCAL > <https://groups.google.com/d/msgid/django-users/f2d2e610ffe04dff85edf80be0c7ad2d%40iss2.ISS.LOCAL?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAH-SnCALGpZGrjVfvkN%2Bt-6Dg6tkX7yW-DhQxyMueTw9rHtqpg%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAH-SnCALGpZGrjVfvkN%2Bt-6Dg6tkX7yW-DhQxyMueTw9rHtqpg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/cbdab94a9c2b481bbddb1b242009de80%40iss2.ISS.LOCAL > <https://groups.google.com/d/msgid/django-users/cbdab94a9c2b481bbddb1b242009de80%40iss2.ISS.LOCAL?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/98d2c65cc3964e0181f4cc4d40a531ba%40iss2.ISS.LOCAL > <https://groups.google.com/d/msgid/django-users/98d2c65cc3964e0181f4cc4d40a531ba%40iss2.ISS.LOCAL?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAH-SnCB5vSmw3d42wN%2BG5t6PnXq-6W9%2B9kpppRET%2B78pw-HQxQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.