'Queryset is Containing some items but all() method returns empty array

I have this code:

print(f"DEBUG 1: {queryset}")
transaction_items = queryset.all()
queryset.update(status=TRANSACTION_STATUS_COMPLETED, processing_method=PROCESSING_METHOD_MANUALLY)
print(f"DEBUG 2: {len(queryset.all())}")

somehow producing this result:

DEBUG 1: <QuerySet [<TransactionItem: TransactionItem object (18259)>, <TransactionItem: TransactionItem object (18258)>]>
DEBUG 2: 0
CHUAKS: [] 0

It's quite weird because the all() method usually return non-empty array because the queryset itself is not empty.

Try to refactor the code to be like this:

def complete_transaction_items_manually(self, request, queryset):
    print(f"DEBUG 1: {queryset}")
    transaction_items = queryset.all()
    print(f"DEBUG 2: {transaction_items}")
    queryset.update(status=TRANSACTION_STATUS_COMPLETED, processing_method=PROCESSING_METHOD_MANUALLY)

Still returning this result:

DEBUG 1: <QuerySet [<TransactionItem: TransactionItem object (18256)>, <TransactionItem: TransactionItem object (18255)>]>
DEBUG 2: <QuerySet []>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source