|
25 | 25 | from onyx.configs.constants import OnyxRedisSignals
|
26 | 26 | from onyx.db.connector import fetch_connector_by_id
|
27 | 27 | from onyx.db.connector_credential_pair import add_deletion_failure_message
|
28 |
| -from onyx.db.connector_credential_pair import ( |
29 |
| - delete_connector_credential_pair__no_commit, |
30 |
| -) |
31 | 28 | from onyx.db.connector_credential_pair import get_connector_credential_pair_from_id
|
32 | 29 | from onyx.db.connector_credential_pair import get_connector_credential_pairs
|
33 |
| -from onyx.db.document import ( |
34 |
| - delete_all_documents_by_connector_credential_pair__no_commit, |
35 |
| -) |
36 | 30 | from onyx.db.document import get_document_ids_for_connector_credential_pair
|
37 | 31 | from onyx.db.document_set import delete_document_set_cc_pair_relationship__no_commit
|
38 | 32 | from onyx.db.engine import get_session_with_current_tenant
|
@@ -449,27 +443,15 @@ def monitor_connector_deletion_taskset(
|
449 | 443 | connector_id_to_delete = cc_pair.connector_id
|
450 | 444 | credential_id_to_delete = cc_pair.credential_id
|
451 | 445 |
|
452 |
| - # Explicitly delete document by connector credential pair records before deleting the connector |
453 |
| - # This is needed because connector_id is a primary key in that table and cascading deletes won't work |
454 |
| - delete_all_documents_by_connector_credential_pair__no_commit( |
455 |
| - db_session=db_session, |
456 |
| - connector_id=connector_id_to_delete, |
457 |
| - credential_id=credential_id_to_delete, |
458 |
| - ) |
| 446 | + # No need to explicitly delete DocumentByConnectorCredentialPair records anymore |
| 447 | + # as we have proper cascade relationships set up in the models |
459 | 448 |
|
460 |
| - # Flush to ensure document deletion happens before connector deletion |
| 449 | + # Flush to ensure all operations happen in sequence |
461 | 450 | db_session.flush()
|
462 | 451 |
|
463 |
| - # Expire the cc_pair to ensure SQLAlchemy doesn't try to manage its state |
464 |
| - # related to the deleted DocumentByConnectorCredentialPair during commit |
465 |
| - db_session.expire(cc_pair) |
| 452 | + # Delete the cc-pair directly |
| 453 | + db_session.delete(cc_pair) |
466 | 454 |
|
467 |
| - # finally, delete the cc-pair |
468 |
| - delete_connector_credential_pair__no_commit( |
469 |
| - db_session=db_session, |
470 |
| - connector_id=connector_id_to_delete, |
471 |
| - credential_id=credential_id_to_delete, |
472 |
| - ) |
473 | 455 | # if there are no credentials left, delete the connector
|
474 | 456 | connector = fetch_connector_by_id(
|
475 | 457 | db_session=db_session,
|
|
0 commit comments