@@ -24,8 +24,6 @@ def delete(self, _id: str) -> int:
2424 get_handler_by_name ("comment_thread_deleted" ).send (
2525 sender = self .__class__ , comment_thread_id = _id
2626 )
27- from forum .backends .mongodb .users import Users
28-
2927 Users ().delete_read_state_by_thread_id (_id )
3028 return result
3129
@@ -323,29 +321,27 @@ def soft_delete(self, thread_id: str, user_id: str) -> int:
323321
324322 # Cascade soft delete to all comments of this thread
325323 if result .modified_count > 0 :
326- from forum .backends .mongodb .comments import Comment
324+ from forum .backends .mongodb .comments import Comment # pylint: disable=import-outside-toplevel,cyclic-import
327325 Comment ().soft_delete_by_thread (thread_id , user_id )
328326
329327 # Delete read states from user model
330328 if result .modified_count > 0 :
331- from forum .backends .mongodb .users import Users
332329 Users ().delete_read_state_by_thread_id (thread_id )
333330
334331 # Update Elasticsearch index to reflect the soft delete
335332 if result .modified_count > 0 :
336333 try :
337- from forum .search .es import ElasticsearchDocumentBackend
338-
334+ from forum .search .es import ElasticsearchDocumentBackend # pylint: disable=import-outside-toplevel
339335 es_backend = ElasticsearchDocumentBackend ()
340336 es_backend .update_document (
341337 index_name = self .index_name ,
342338 doc_id = thread_id ,
343339 update_data = {"is_deleted" : True },
344340 )
345- except Exception as e :
341+ except Exception as e : # pylint: disable=broad-exception-caught
346342 # Log the error but don't fail the soft delete operation
347343 # Elasticsearch updates are not critical for the soft delete to succeed
348- import logging
344+ import logging # pylint: disable=import-outside-toplevel
349345 log = logging .getLogger (__name__ )
350346 log .warning (f"Failed to update Elasticsearch for thread { thread_id } : { e } " )
351347
@@ -367,18 +363,17 @@ def restore(self, thread_id: str) -> int:
367363 # Update Elasticsearch index to reflect the restore
368364 if result .modified_count > 0 :
369365 try :
370- from forum .search .es import ElasticsearchDocumentBackend
371-
366+ from forum .search .es import ElasticsearchDocumentBackend # pylint: disable=import-outside-toplevel
372367 es_backend = ElasticsearchDocumentBackend ()
373368 es_backend .update_document (
374369 index_name = self .index_name ,
375370 doc_id = thread_id ,
376371 update_data = {"is_deleted" : False },
377372 )
378- except Exception as e :
373+ except Exception as e : # pylint: disable=broad-exception-caught
379374 # Log the error but don't fail the restore operation
380375 # Elasticsearch updates are not critical for the restore to succeed
381- import logging
376+ import logging # pylint: disable=import-outside-toplevel
382377 log = logging .getLogger (__name__ )
383378 log .warning (f"Failed to update Elasticsearch for thread { thread_id } : { e } " )
384379
0 commit comments