I need count in subquery. Example at http://docs.peewee-orm.com/en/latest/peewee/hacks.html#other-methods
My code:
subquery_condition = (UserSurvey.user == User.id) & (UserSurvey.is_current == False)
subquery = (UserSurvey.select(fn.COUNT(UserSurvey.id)).where(subquery_condition))
condition = User.next_notify & (User.next_notify <= dt_now) & (subquery == 0)
I receive error:
Traceback (most recent call last):
File "/mnt/d/projects/venvs/survey_bot/lib/python3.8/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/mnt/d/projects/venvs/survey_bot/lib/python3.8/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/mnt/d/projects/venvs/survey_bot/lib/python3.8/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, *ctx.params)
File "/mnt/d/projects/venvs/survey_bot/lib/python3.8/site-packages/click/core.py", line 555, in invoke
return callback(args, **kwargs)
File "/mnt/d/projects/survey_bot/project/tlgrm.py", line 37, in notifications
dialog_bot.send_notifications()
File "/mnt/d/projects/survey_bot/project/telegram_dialog/bot.py", line 280, in send_notifications
users = get_user_for_notifications()
File "/mnt/d/projects/survey_bot/project/views/user.py", line 103, in get_user_for_notifications
condition = User.next_notify & (User.next_notify <= dt_now) & (subquery == 0)
File "/mnt/d/projects/venvs/survey_bot/lib/python3.8/site-packages/peewee.py", line 817, in __eq__
return self._hash == other._hash
AttributeError: 'int' object has no attribute '_hash'Process finished with exit code 1
Fixed. As a workaround until I tag a new release, you can use:
Expression(subquery, OP.EQ, 0)
Instead of subquery == 0.
Most helpful comment
Fixed. As a workaround until I tag a new release, you can use:
Instead of
subquery == 0.