66# from merge_attributes import *; w = main(9)
77
88
9+ def remove_by_id (uid : str ) -> tuple [str , str ]:
10+ try :
11+ with transaction .atomic ():
12+ query = Attribute .objects .filter (payload = uid )
13+
14+ assert query .count () == 2 , "Count != 2"
15+
16+ a_from , a_to = query
17+
18+ assert not a .from_children .count (), "Attr has Children"
19+
20+ with connection .cursor () as cursor : cursor .execute (
21+ """
22+ update attribute_group_attribute
23+ set attribute_id = %s
24+ where attribute_id = %s;
25+ """ ,
26+ [a_to .id , a_from .id ]
27+ )
28+
29+ a_from .projectgoal_set .update (attribute_id = a_to .id )
30+
31+ assert not a_from .attributegroup_set .count (), "Attribute group not remapped"
32+ assert not a_from .projectgoal_set .count (), "Projectgoal not remapped"
33+ assert (d := a_from .delete ())[0 ] == 1 , "Unexpected delete"
34+
35+ return None
36+ except Exception as e : return (uid , str (e ))
37+
38+
39+
940def traverse (access ):
1041 data = access .values_list ("name" , flat = True )
1142 count = Counter (data )
@@ -21,9 +52,6 @@ def traverse(access):
2152 a_from , a_to = access .filter (name = name )
2253 if a_from .payload != None : a_from , a_to = a_to , a_from
2354
24- # a_to = access.get(name=name, payload__isnull=False)
25- # a_from = access.get(name=name, payload__isnull=True)
26-
2755 print ("from " + a_to .parent .name if a_to .parent else "" )
2856
2957 with connection .cursor () as cursor : cursor .execute (
0 commit comments