From 9753ef02c3fe6bafe4deadcda4d9d148f72a74bc Mon Sep 17 00:00:00 2001 From: ZiWei <131428629+ZiWei09@users.noreply.github.com> Date: Mon, 12 Jan 2026 10:50:28 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8DBottle=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E5=BA=8F=E5=88=97=E5=8C=96=E5=92=8C=E5=8F=8D=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unilabos/resources/itemized_carrier.py | 35 +++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/unilabos/resources/itemized_carrier.py b/unilabos/resources/itemized_carrier.py index a5207d4..2f5cfd7 100644 --- a/unilabos/resources/itemized_carrier.py +++ b/unilabos/resources/itemized_carrier.py @@ -50,13 +50,46 @@ class Bottle(Well): self.barcode = barcode def serialize(self) -> dict: + # Pylabrobot expects barcode to be an object with serialize(), but here it is a str. + # We temporarily unset it to avoid AttributeError in super().serialize(). + _barcode = self.barcode + self.barcode = None + try: + data = super().serialize() + finally: + self.barcode = _barcode + return { - **super().serialize(), + **data, "diameter": self.diameter, "height": self.height, "barcode": self.barcode, } + @classmethod + def deserialize(cls, data: dict, allow_marshal: bool = False): + # Extract barcode before calling parent deserialize to avoid type error + barcode_data = data.pop("barcode", None) + + # Call parent deserialize + instance = super(Bottle, cls).deserialize(data, allow_marshal=allow_marshal) + + # Set barcode as string (not as Barcode object) + if barcode_data: + if isinstance(barcode_data, str): + instance.barcode = barcode_data + elif isinstance(barcode_data, dict): + # If it's a dict (Barcode serialized format), extract the data field + instance.barcode = barcode_data.get("data", "") + else: + instance.barcode = "" + + # Set additional attributes + instance.diameter = data.get("diameter", instance._size_x) + instance.height = data.get("height", instance._size_z) + + return instance + T = TypeVar("T", bound=ResourceHolder) S = TypeVar("S", bound=ResourceHolder)