Skip to content

Commit 98f5f8b

Browse files
committed
box: get/remove return None if not found #32
1 parent aeeac82 commit 98f5f8b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

objectbox/box.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ def get(self, id: int):
112112
with self._ob.read_tx():
113113
c_data = ctypes.c_void_p()
114114
c_size = ctypes.c_size_t()
115-
obx_box_get(self._c_box, id, ctypes.byref(
116-
c_data), ctypes.byref(c_size))
117-
115+
try:
116+
obx_box_get(self._c_box, id, ctypes.byref(
117+
c_data), ctypes.byref(c_size))
118+
except NotFoundException:
119+
return None
118120
data = c_voidp_as_bytes(c_data, c_size.value)
119121
return self._entity.unmarshal(data)
120122

@@ -143,7 +145,11 @@ def remove(self, id_or_object):
143145
id = self._entity.get_object_id(id_or_object)
144146
else:
145147
id = id_or_object
146-
obx_box_remove(self._c_box, id)
148+
try:
149+
obx_box_remove(self._c_box, id)
150+
return True
151+
except NotFoundException:
152+
return False
147153

148154
def remove_all(self) -> int:
149155
count = ctypes.c_uint64()

0 commit comments

Comments
 (0)