Inefficient Transaction Update Operation #80

Closed
opened 2025-12-28 23:25:24 +01:00 by adam · 1 comment
Owner

Originally created by @SerafimPikalov on GitHub (Dec 7, 2025).

The perform_update method in TransactionViewSet accesses serializer.data["pk"] which triggers unnecessary full serialization of the transaction object, then fetches the same object from the database again. This is inefficient and can cause issues in edge cases.

Steps to Reproduce:

  1. Update any transaction via PATCH/PUT request to /api/transactions/{id}/
  2. Observe the unnecessary serialization and database query in logs/debugger

Expected Behavior:
The update operation should use the instance directly from the serializer without triggering serialization or additional database queries.

Actual Behavior:
The code:

  1. Triggers full serialization via serializer.data["pk"]
  2. Fetches the object from database again using Transaction.objects.get(pk=...)
  3. Creates unnecessary overhead and potential race conditions
Originally created by @SerafimPikalov on GitHub (Dec 7, 2025). The `perform_update` method in `TransactionViewSet` accesses `serializer.data["pk"]` which triggers unnecessary full serialization of the transaction object, then fetches the same object from the database again. This is inefficient and can cause issues in edge cases. Steps to Reproduce: 1. Update any transaction via PATCH/PUT request to `/api/transactions/{id}/` 2. Observe the unnecessary serialization and database query in logs/debugger Expected Behavior: The update operation should use the instance directly from the serializer without triggering serialization or additional database queries. Actual Behavior: The code: 1. Triggers full serialization via `serializer.data["pk"]` 2. Fetches the object from database again using `Transaction.objects.get(pk=...)` 3. Creates unnecessary overhead and potential race conditions
adam closed this issue 2025-12-28 23:25:25 +01:00
Author
Owner

@eitchtee commented on GitHub (Dec 7, 2025):

Dang, nice catch.

I will update the function to use self.get_object() which should be more efficient. Thank you!

@eitchtee commented on GitHub (Dec 7, 2025): Dang, nice catch. I will update the function to use `self.get_object()` which should be more efficient. Thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WYGIWYH#80