Magesh Ravi
Artist | Techie | Entrepreneur
I noticed something weird in the Django ORM while using queryset.values_list()
and queryset.update()
together.
from subscriptions.models import PurchaseOrder
# get queryset
purchase_orders = PurchaseOrder.objects.filter(status=PurchaseOrder.Status.HALTED)
# get values-queryset
po_values_list = purchase_orders.values_list("razorpay_order_id", flat=True)
print(po_values_list) # prints non-empty queryset
# update using queryset.update() resets the values_list
purchase_orders.update(status=PurchaseOrder.Status.CREATED)
print(po_values_list) # prints empty queryset
queryset.update()
or instance.update()
within a for-loop, this happens.I haven't tried picking the values-list. I'm still trying to understand why this is happening.