Skip to content

Commit

Permalink
Merge pull request #135 from zhuzhongshu123/0.6_dev
Browse files Browse the repository at this point in the history
fix(common): fix zodb writer bug
  • Loading branch information
zhuzhongshu123 authored Dec 16, 2024
2 parents 519dbcf + 958f341 commit b7e074d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion kag/builder/default_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def get_component_with_ckpts(self):
self.extractor,
self.vectorizer,
self.post_processor,
self.writer,
]

def close_checkpointers(self):
Expand Down
5 changes: 3 additions & 2 deletions kag/builder/model/sub_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied.
import pprint
import copy
from typing import Dict, List, Any

from kag.builder.model.spg_record import SPGRecord
Expand Down Expand Up @@ -48,7 +49,7 @@ def to_dict(self):
"id": self.id,
"name": self.name,
"label": self.label,
"properties": self.properties,
"properties": copy.deepcopy(self.properties),
}

@classmethod
Expand Down Expand Up @@ -119,7 +120,7 @@ def to_dict(self):
"fromType": self.from_type,
"toType": self.to_type,
"label": self.label,
"properties": self.properties,
"properties": copy.deepcopy(self.properties),
}

@classmethod
Expand Down
9 changes: 6 additions & 3 deletions kag/common/checkpointer/bin_checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging
import transaction
import threading

import pickle
import BTrees.OOBTree
from ZODB import DB
from ZODB.FileStorage import FileStorage
Expand Down Expand Up @@ -135,7 +135,10 @@ def read_from_ckpt(self, key):
with self._lock:
with self._ckpt.transaction() as conn:
obj = conn.root.data.get(key, None)
return obj
if obj:
return pickle.loads(obj)
else:
return None

def write_to_ckpt(self, key, value):
"""
Expand All @@ -148,7 +151,7 @@ def write_to_ckpt(self, key, value):
with self._lock:
try:
with self._ckpt.transaction() as conn:
conn.root.data[key] = value
conn.root.data[key] = pickle.dumps(value)
except Exception as e:
logger.warn(f"failed to write checkpoint {key} to db, info: {e}")

Expand Down

0 comments on commit b7e074d

Please sign in to comment.