Skip to content

Commit f228834

Browse files
greenrobotloryruta
authored andcommitted
Minor improvements during review #25
E.g. add reset_ids() for ID sync tests to ensure not to use already assigned IDs from last ID sync.
1 parent 6c5a78e commit f228834

5 files changed

Lines changed: 75 additions & 315 deletions

File tree

objectbox/box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def get_all(self) -> list:
141141
finally:
142142
obx_bytes_array_free(c_bytes_array_p)
143143

144-
def remove(self, id_or_object):
144+
def remove(self, id_or_object) -> bool:
145145
if isinstance(id_or_object, self._entity.user_type):
146146
id = self._entity.get_object_id(id_or_object)
147147
else:

objectbox/model/entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def unmarshal(self, data: bytes):
234234
size = table.VectorLen(o)
235235
# slice the vector as a requested type
236236
val = prop._py_type(table.Bytes[start:start + size])
237-
elif prop._ob_type == OBXPropertyType_ShortVector:
237+
elif ob_type == OBXPropertyType_ShortVector:
238238
val = table.GetVectorAsNumpy(flatbuffers.number_types.Int16Flags, o)
239239
elif ob_type == OBXPropertyType_CharVector:
240240
val = table.GetVectorAsNumpy(flatbuffers.number_types.Int16Flags, o)

objectbox/model/model.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def __init__(self):
3232

3333
def entity(self, entity: _Entity):
3434
if not isinstance(entity, _Entity):
35-
raise Exception(f"Given type is not an Entity ({type(entity)}). "
36-
f"Maybe did you forget the @Entity annotation?")
35+
raise Exception(f"The given type is not an Entity: {type(entity)}. "
36+
f"Ensure to have an @Entity annotation on the class.")
3737
for other_entity in self.entities: # Linear search (we should't have many entities)
3838
if entity.name == other_entity.name:
3939
raise Exception(f"Duplicate entity: \"{entity.name}\"")
@@ -46,20 +46,20 @@ def validate_ids_assigned(self):
4646
for entity in self.entities:
4747
has_properties = len(entity.properties) > 0
4848
if not entity.iduid.is_assigned():
49-
raise ValueError(f"Entity \"{entity.name}\" ID not assigned")
49+
raise ValueError(f"Entity \"{entity.name}\" ID/UID not assigned")
5050
for prop in entity.properties:
5151
if not prop.iduid.is_assigned():
52-
raise ValueError(f"Property \"{entity.name}.{prop.name}\" ID not assigned")
52+
raise ValueError(f"Property \"{entity.name}.{prop.name}\" ID/UID not assigned")
5353
if prop.index is not None:
5454
has_indices = True
5555
if not prop.index.iduid.is_assigned():
56-
raise ValueError(f"Property index \"{entity.name}.{prop.name}\" ID not assigned")
56+
raise ValueError(f"Property index \"{entity.name}.{prop.name}\" ID/UID not assigned")
5757
if has_properties and not entity.last_property_iduid.is_assigned():
58-
raise ValueError(f"Entity \"{entity.name}\" last_property_iduid not assigned")
58+
raise ValueError(f"Entity \"{entity.name}\" last property ID/UID not assigned")
5959
if has_entities and not self.last_entity_iduid.is_assigned():
60-
raise Exception("Model last_entity_iduid not assigned")
60+
raise ValueError("Last entity ID/UID not assigned")
6161
if has_indices and not self.last_index_iduid.is_assigned():
62-
raise ValueError("Model last_index_iduid not assigned")
62+
raise ValueError("Last index ID/UID not assigned")
6363

6464
def _set_hnsw_params(self, index: HnswIndex):
6565
if index.dimensions is not None:

obx-model.json

Lines changed: 0 additions & 265 deletions
This file was deleted.

0 commit comments

Comments
 (0)