@@ -171,6 +171,7 @@ def process_vocabulary_reference_by_value(self, node):
171
171
172
172
search_field = None
173
173
inverse_search_field = None
174
+ perform_inversion_fix = False
174
175
if self .ctx .enable_relation_vocabulary_column_logic and 'Relationship' in vocabulary_name :
175
176
parent = node .getparent ()
176
177
if parent == None :
@@ -197,6 +198,8 @@ def process_vocabulary_reference_by_value(self, node):
197
198
else :
198
199
search_field = 'Relationship type'
199
200
inverse_search_field = 'Reverse relationship'
201
+ perform_inversion_fix = True
202
+
200
203
elif entity_type_in_relation_count == 2 :
201
204
search_field = 'Relationship type'
202
205
inverse_search_field = 'Reverse relationship'
@@ -210,27 +213,31 @@ def process_vocabulary_reference_by_value(self, node):
210
213
# If failed, try to find the value in the other column (assuming the value was stored incorrectly)
211
214
new_record_id = self .ctx .api .find_record (self .ctx , vocabulary_id , value , search_field = inverse_search_field )
212
215
old_value = node .text
213
- record_data = self .ctx .api .lookup_record (new_record_id )
214
-
215
- v = self .ctx .api .lookup_vocabulary (record_data ['vocabularyId' ])
216
- s = self .ctx .api .lookup_schema (v ['schemaId' ])
217
- ids = [d ['id' ] for d in s ['definitions' ] if d ['name' ] == search_field ] # We need the value, that we actually originally searched for
218
- if len (ids ) != 1 :
219
- logging .critical (f'Non unique "{ search_field } " fields found: { ids } !' )
220
- sys .exit (1 )
221
-
222
- field_data = [f for f in record_data ['fields' ] if f ['definitionId' ] == ids [0 ]]
223
- if len (field_data ) != 1 :
224
- logging .critical (f'Record [{ new_record_id } ] has no unique search column entry field' )
225
- sys .exit (1 )
226
-
227
- # Replace node text if not matching any translation of main value
228
- translated_main_values = self .ctx .extract_language_values (field_data [0 ])
229
- new_value = self .ctx .extract_preferred_language (translated_main_values )
230
-
231
- #dump_node(node)
232
- logging .warn (f'Relation [{ vocabulary_name } ] is saved in the wrong direction, correct direction found and corrected: "{ old_value } " -> "{ new_value } "' )
233
- node .text = new_value
216
+
217
+ if perform_inversion_fix :
218
+ record_data = self .ctx .api .lookup_record (new_record_id )
219
+
220
+ v = self .ctx .api .lookup_vocabulary (record_data ['vocabularyId' ])
221
+ s = self .ctx .api .lookup_schema (v ['schemaId' ])
222
+ ids = [d ['id' ] for d in s ['definitions' ] if d ['name' ] == search_field ] # We need the value, that we actually originally searched for
223
+ if len (ids ) != 1 :
224
+ logging .critical (f'Non unique "{ search_field } " fields found: { ids } !' )
225
+ sys .exit (1 )
226
+
227
+ field_data = [f for f in record_data ['fields' ] if f ['definitionId' ] == ids [0 ]]
228
+ if len (field_data ) != 1 :
229
+ logging .critical (f'Record [{ new_record_id } ] has no unique search column entry field' )
230
+ sys .exit (1 )
231
+
232
+ # Replace node text if not matching any translation of main value
233
+ translated_main_values = self .ctx .extract_language_values (field_data [0 ])
234
+ new_value = self .ctx .extract_preferred_language (translated_main_values )
235
+
236
+ #dump_node(node)
237
+ logging .warn (f'Relation [{ vocabulary_name } ] is saved in the wrong direction, correct direction found and corrected: "{ old_value } " -> "{ new_value } "' )
238
+ node .text = new_value
239
+ else :
240
+ logging .debug (f'Relation [{ vocabulary_name } ] value "{ value } " found in column "{ inverse_search_field } ", keeping as is' )
234
241
235
242
else :
236
243
new_record_id = self .ctx .api .find_record (self .ctx , vocabulary_id , value , search_field = None )
0 commit comments