From 116046a8b2a90b3e71ad0522831b0e23438c0065 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 27 Oct 2021 14:06:04 +0200 Subject: [PATCH] Fix binding printer_id to response callbacks With the lambda it would capture the variable of printer_id. It wouldn't actually store the value of printer_id in teh created lambda. As a result, it was using the current value of printer_id when the lambda executes, rather than the value of printer_id when the lambda is constructed. A bit weird how that works in Python's lambdas. With partial functions it works properly. Contributes to issue CURA-8609. --- cura/PrinterOutput/UploadMaterialsJob.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cura/PrinterOutput/UploadMaterialsJob.py b/cura/PrinterOutput/UploadMaterialsJob.py index ebadb35257..166b692ea5 100644 --- a/cura/PrinterOutput/UploadMaterialsJob.py +++ b/cura/PrinterOutput/UploadMaterialsJob.py @@ -2,6 +2,7 @@ # Cura is released under the terms of the LGPLv3 or higher. import enum +import functools # For partial methods to use as callbacks with information pre-filled. import json # To serialise metadata for API calls. import os # To delete the archive when we're done. from PyQt5.QtCore import QUrl @@ -177,8 +178,8 @@ class UploadMaterialsJob(Job): http = HttpRequestManager.getInstance() http.post( url = self.UPLOAD_CONFIRM_URL.format(cluster_id = cluster_id, cluster_printer_id = printer_id), - callback = lambda reply: self.onUploadConfirmed(printer_id, reply, None), - error_callback = lambda reply, error: self.onUploadConfirmed(printer_id, reply, error), # Let this same function handle the error too. + callback = functools.partial(self.onUploadConfirmed, printer_id), + error_callback = functools.partial(self.onUploadConfirmed, printer_id), # Let this same function handle the error too. scope = self._scope, data = json.dumps({"data": {"material_profile_id": self._archive_remote_id}}).encode("UTF-8") )