diff --git a/src/steps/crm/akte/akte_sync_event_step.py b/src/steps/crm/akte/akte_sync_event_step.py index dc90629..1d0549b 100644 --- a/src/steps/crm/akte/akte_sync_event_step.py +++ b/src/steps/crm/akte/akte_sync_event_step.py @@ -684,11 +684,17 @@ async def _run_ragflow_sync( ctx.logger.info( f" ⏭️ Nicht unterstützter Dateityp ({mime_type}) – übersprungen" ) - if not ragflow_doc_id: - await espocrm.update_entity('CDokumente', doc_id, { - 'aiSyncStatus': 'unsupported', - 'aiLastSync': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), - }) + # If doc was previously uploaded to RAGflow (e.g. type changed), remove it + if ragflow_doc_id: + try: + await ragflow.remove_document(dataset_id, ragflow_doc_id) + ctx.logger.info(f" 🗑️ Aus RAGflow entfernt (nicht unterstützt): {ragflow_doc_id}") + except Exception as e: + ctx.logger.warn(f" ⚠️ RAGflow-Löschung fehlgeschlagen: {e}") + await espocrm.update_entity('CDokumente', doc_id, { + 'aiSyncStatus': 'unsupported', + 'aiLastSync': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), + }) skipped += 1 continue