Bearle/django-coinpayments

refresh_tx_info fails because of exclude()

rubik opened this issue · 2 comments

rubik commented
  • django-coinpayments version: 0.1.0
  • Django version: 2.0.1
  • Python version: 3.6.5
  • Operating System: ArchLinux

Description

I tried to run refresh_tx_info but the program fails while inside the method PaymentManager.get_pending_payments, because it calls the exclude method in an incorrect way.

What I Did

In [17]: refresh_tx_info()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-0374e3a88753> in <module>()
----> 1 refresh_tx_info()

lib/python3.6/site-packages/celery/local.py in __call__(self, *a, **kw)
    189 
    190     def __call__(self, *a, **kw):
--> 191         return self._get_current_object()(*a, **kw)
    192 
    193     def __len__(self):

lib/python3.6/site-packages/celery/app/task.py in __call__(self, *args, **kwargs)
    378             if self.__self__ is not None:
    379                 return self.run(self.__self__, *args, **kwargs)
--> 380             return self.run(*args, **kwargs)
    381         finally:
    382             self.pop_request()

lib/python3.6/site-packages/django_coinpayments/tasks.py in refresh_tx_info()
     12 def refresh_tx_info():
     13     caller = CoinPayments.get_instance()
---> 14     objects = Payment.objects.get_pending_payments().order_by('id')
     15     # 25 because of https://www.coinpayments.net/apidoc-get-tx-info
     16     paginator = Paginator(objects, 25)

lib/python3.6/site-packages/django_coinpayments/models.py in get_pending_payments(self)
     60         return self.get_queryset() \
     61             .filter(status__in=[self.model.PAYMENT_STATUS_PENDING]) \
---> 62             .exclude(self.get_late_payments())
     63 
     64     def get_successful_payments(self):

lib/python3.6/site-packages/django/db/models/query.py in exclude(self, *args, **kwargs)
    841         set.
    842         """
--> 843         return self._filter_or_exclude(True, *args, **kwargs)
    844 
    845     def _filter_or_exclude(self, negate, *args, **kwargs):

lib/python3.6/site-packages/django/db/models/query.py in _filter_or_exclude(self, negate, *args, **kwargs)
    850         clone = self._chain()
    851         if negate:
--> 852             clone.query.add_q(~Q(*args, **kwargs))
    853         else:
    854             clone.query.add_q(Q(*args, **kwargs))

lib/python3.6/site-packages/django/db/models/sql/query.py in add_q(self, q_object)
   1251         # So, demotion is OK.
   1252         existing_inner = {a for a in self.alias_map if self.alias_map[a].join_type == INNER}
-> 1253         clause, _ = self._add_q(q_object, self.used_aliases)
   1254         if clause:
   1255             self.where.add(clause, AND)

lib/python3.6/site-packages/django/db/models/sql/query.py in _add_q(self, q_object, used_aliases, branch_negated, current_negated, allow_joins, split_subq)
   1275                     child, can_reuse=used_aliases, branch_negated=branch_negated,
   1276                     current_negated=current_negated, allow_joins=allow_joins,
-> 1277                     split_subq=split_subq,
   1278                 )
   1279                 joinpromoter.add_votes(needed_inner)

lib/python3.6/site-packages/django/db/models/sql/query.py in build_filter(self, filter_expr, branch_negated, current_negated, can_reuse, allow_joins, split_subq, reuse_with_filtered_relation)
   1148         if isinstance(filter_expr, dict):
   1149             raise FieldError("Cannot parse keyword query as dict")
-> 1150         arg, value = filter_expr
   1151         if not arg:
   1152             raise FieldError("Cannot parse keyword query %r" % arg)

ValueError: not enough values to unpack (expected 2, got 1)
rubik commented

I created a PR with a proposed fix. I hope you can merge it as soon as possible because this package is really useful and I'd like to avoid having to vendorize it.

Thanks, looks like a typo =)