Commit 50a760f7 authored by Jan Reimes's avatar Jan Reimes
Browse files

fix(db): deserialize metadata_payload and handle missing JSON

- Deserialize metadata_payload field when loaded from DB if it's a JSON string\n- Preserve empty object on JSON decode error\n- Fix except syntax in pool_executors factory import
parent 1d814557
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ try:
    from concurrent.futures import InterpreterPoolExecutor  # noqa: PLC0415

    HAS_INTERPRETER_POOL_EXECUTOR = True
except (ImportError, AttributeError):
except ImportError, AttributeError:
    InterpreterPoolExecutor = None  # type: ignore[assignment, misc]
    HAS_INTERPRETER_POOL_EXECUTOR = False

+9 −2
Original line number Diff line number Diff line
@@ -704,7 +704,7 @@ class TDocDatabase:
                        try:
                            if "T" in value and value.endswith(("Z", "+00:00")):
                                row_dict[key] = datetime.fromisoformat(value)
                        except (ValueError, AttributeError):
                        except ValueError, AttributeError:
                            pass
                if table == "spec_source_records":
                    metadata_payload = row_dict.get("metadata_payload")
@@ -750,7 +750,14 @@ class TDocDatabase:

    def _get_spec_source_record(self, record_id: str) -> SpecificationSourceRecord | None:
        try:
            return self.connection.model_from_table("spec_source_records", record_id)  # type: ignore[arg-type]
            record = self.connection.model_from_table("spec_source_records", record_id)  # type: ignore[arg-type]
            # Handle JSON deserialization for metadata_payload field
            if record is not None and isinstance(record.metadata_payload, str):
                try:
                    record = record.model_copy(update={"metadata_payload": json.loads(record.metadata_payload)})
                except json.JSONDecodeError:
                    record = record.model_copy(update={"metadata_payload": {}})
            return record
        except KeyError:
            return None

+1 −1

File changed.

Contains only whitespace changes.