Skip to content

Commit 1ee4753

Browse files
committed
model: fix validate_ids_assigned #25
1 parent 63bc70c commit 1ee4753

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

objectbox/model/model.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,26 @@ def entity(self, entity: _Entity):
4040
self.entities.append(entity)
4141

4242
def validate_ids_assigned(self):
43-
if not self.last_entity_iduid.is_assigned():
44-
raise Exception("Model last_entity_id not assigned")
45-
if not self.last_entity_iduid.is_assigned():
46-
raise ValueError("Model last_index_id not assigned")
47-
# if not self.last_relation_id.is_assigned(): TODO last_relation_id
48-
# return False
49-
# TODO validate last_entity_id value
50-
# TODO validate last_index_id value
43+
# TODO validate last_relation_iduid
44+
has_entities = len(self.entities) > 0
45+
has_indices = False
5146
for entity in self.entities:
47+
has_properties = len(entity.properties) > 0
5248
if not entity.iduid.is_assigned():
53-
raise ValueError(f"Entity \"{entity.name}\" id not assigned")
49+
raise ValueError(f"Entity \"{entity.name}\" ID not assigned")
5450
for prop in entity.properties:
55-
# TODO validate last_property_id value
5651
if not prop.iduid.is_assigned():
57-
raise ValueError(f"Property \"{entity.name}\"->\"{prop.name}\" id not assigned")
58-
if not entity.last_property_iduid.is_assigned():
59-
raise ValueError(f"Entity \"{entity.name}\" last_property_id not assigned")
52+
raise ValueError(f"Property \"{entity.name}.{prop.name}\" ID not assigned")
53+
if prop.index is not None:
54+
has_indices = True
55+
if not prop.index.iduid.is_assigned():
56+
raise ValueError(f"Property index \"{entity.name}.{prop.name}\" ID not assigned")
57+
if has_properties and not entity.last_property_iduid.is_assigned():
58+
raise ValueError(f"Entity \"{entity.name}\" last_property_iduid not assigned")
59+
if has_entities and not self.last_entity_iduid.is_assigned():
60+
raise Exception("Model last_entity_iduid not assigned")
61+
if has_indices and not self.last_index_iduid.is_assigned():
62+
raise ValueError("Model last_index_iduid not assigned")
6063

6164
def _set_hnsw_params(self, index: HnswIndex):
6265
if index.dimensions is not None:

0 commit comments

Comments
 (0)