This commit is contained in:
anhduy-tech
2026-02-09 16:56:55 +07:00
parent d6eec950e9
commit c2efa46260
37 changed files with 199 additions and 121 deletions

View File

@@ -58,9 +58,18 @@ def generic_post_save_handler(sender, instance, created, **kwargs):
"""
def send_update_after_commit():
change_type = "created" if created else "updated"
# Re-fetch the instance to ensure we have the committed data
refreshed_instance = sender.objects.get(pk=instance.pk)
send_model_update(refreshed_instance, change_type)
try:
# Re-fetch the instance to ensure we have the committed data
refreshed_instance = sender.objects.get(pk=instance.pk)
send_model_update(refreshed_instance, change_type)
except sender.DoesNotExist:
# Object đã bị xóa (ví dụ: delete_entry vừa xóa Internal_Entry)
# Bỏ qua việc gửi update, hoặc gửi thông báo "deleted" nếu cần
print(f"Object {sender.__name__} {instance.pk} đã bị xóa, bỏ qua gửi update.")
# Optional: vẫn gửi "deleted" để frontend biết object không còn
send_model_update(instance, "deleted")
except Exception as exc:
print(f"Lỗi trong send_update_after_commit: {exc}")
transaction.on_commit(send_update_after_commit)