Commit 7697516c authored by Julien Cristau's avatar Julien Cristau
Browse files

[schema sync] Update repo._type_source_cache when renaming an entity (closes #2094470)

When an entity type is renamed as part of a migration, it leaves stale
entries in repo._type_source_cache, which makes subsequent operations on
those entities fail (they look for the old entity name instead of the
new one).
parent 71d9fb78b772
......@@ -300,6 +300,9 @@ class CWETypeRenameOp(MemSchemaOperation):
self.info('renamed table %s to %s', oldname, newname)
sqlexec('UPDATE entities SET type=%(newname)s WHERE type=%(oldname)s',
{'newname': newname, 'oldname': oldname})
for eid, (etype, uri, extid, auri) in self.session.repo._type_source_cache.items():
if etype == oldname:
self.session.repo._type_source_cache[eid] = (newname, uri, extid, auri)
sqlexec('UPDATE deleted_entities SET type=%(newname)s WHERE type=%(oldname)s',
{'newname': newname, 'oldname': oldname})
# XXX transaction records
......
......@@ -120,6 +120,10 @@ class Personne(EntityType):
concerne2 = SubjectRelation(('Affaire', 'Note'), cardinality='1*')
connait = SubjectRelation('Personne', symmetric=True)
class New(EntityType):
new_name = String()
class Societe(WorkflowableEntityType):
__permissions__ = {
'read': ('managers', 'users', 'guests'),
......
......@@ -128,6 +128,9 @@ class Personne(EntityType):
inline2 = SubjectRelation('Affaire', inlined=True, cardinality='?*')
class Old(EntityType):
name = String()
class connait(RelationType):
symmetric = True
......
......@@ -234,6 +234,12 @@ class MigrationCommandsTC(CubicWebTC):
self.assertFalse(self.execute('State X WHERE NOT X state_of WF'))
self.assertFalse(self.execute('Transition X WHERE NOT X transition_of WF'))
def test_rename_entity_type(self):
entity = self.mh.create_entity('Old', name=u'old')
self.repo.type_and_source_from_eid(entity.eid)
self.mh.cmd_rename_entity_type('Old', 'New')
self.mh.cmd_rename_attribute('New', 'name', 'new_name')
def test_add_drop_relation_type(self):
self.mh.cmd_add_entity_type('Folder2', auto=False)
self.mh.cmd_add_relation_type('filed_under2')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment