1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2026-07-01 13:20:48 +02:00

MigrationHandler enhancement (now records Model's hash for each changes). Better beaviour of Model.create_component if MigrationHandler raises

This commit is contained in:
Yann 2015-07-24 17:21:50 +02:00
commit 084b8af6c1
3 changed files with 21 additions and 3 deletions

View file

@ -61,10 +61,13 @@ class EmComponent(object):
## @brief Reimplementation for calling the migration handler to register the change
def __setattr__(self, attr_name, value):
if '_inited' in self.__dict__:
inited = '_inited' in self.__dict__
if inited:
# if fails raise MigrationHandlerChangeError
self.model.migration_handler.register_change(self.uid, {attr_name: getattr(self, attr_name) }, {attr_name: value} )
super(EmComponent, self).__setattr__(attr_name, value)
if inited:
self.model.migration_handler.register_model_state(hash(self.model))
## Check the type of attribute named var_name
# @param var_name str : the attribute name

View file

@ -36,4 +36,8 @@ class DummyMigrationHandler(object):
print(str_chg)
print("##############\n")
pass
def register_model_state(self, state_hash):
if self.debug:
print("New EditorialModel sate registered : '%s'"%state_hash)

View file

@ -147,7 +147,16 @@ class Model(object):
em_component.init_ended()
#register the creation in migration handler
self.migration_handler.register_change(em_component.uid, None, em_component.attr_dump)
try:
self.migration_handler.register_change(em_component.uid, None, em_component.attr_dump)
except MigrationHandlerChangeError as e:
#Revert the creation
self.components(em_component.__class__).remove(em_component)
del self._components['uids'][em_component.uid]
print(self._components)
raise e
self.migration_handler.register_model_state(hash(self))
return em_component
@ -166,6 +175,8 @@ class Model(object):
if em_component.delete_check():
self._components[self.name_from_emclass(em_component.__class__)].remove(em_component)
del self._components['uids'][uid]
#Register the new EM state
self.migration_handler.register_model_state(hash(self))
return True
## Changes the current backend