diff --git a/backend/ee/onyx/external_permissions/confluence/doc_sync.py b/backend/ee/onyx/external_permissions/confluence/doc_sync.py index 708be895d..bd78a8ead 100644 --- a/backend/ee/onyx/external_permissions/confluence/doc_sync.py +++ b/backend/ee/onyx/external_permissions/confluence/doc_sync.py @@ -67,6 +67,13 @@ def _get_server_space_permissions( else: logger.warning(f"Email for user {user_name} not found in Confluence") + if not user_emails and not group_names: + logger.warning( + "No user emails or group names found in Confluence space permissions" + f"\nSpace key: {space_key}" + f"\nSpace permissions: {space_permissions}" + ) + return ExternalAccess( external_user_emails=user_emails, external_user_group_ids=group_names, diff --git a/backend/onyx/connectors/confluence/onyx_confluence.py b/backend/onyx/connectors/confluence/onyx_confluence.py index ea8a7a67e..d95fa1963 100644 --- a/backend/onyx/connectors/confluence/onyx_confluence.py +++ b/backend/onyx/connectors/confluence/onyx_confluence.py @@ -121,6 +121,7 @@ def handle_confluence_rate_limit(confluence_call: F) -> F: _DEFAULT_PAGINATION_LIMIT = 1000 +_MINIMUM_PAGINATION_LIMIT = 50 class OnyxConfluence(Confluence): @@ -204,24 +205,41 @@ class OnyxConfluence(Confluence): # If the problematic expansion is in the url, replace it # with the replacement expansion and try again # If that fails, raise the error - if _PROBLEMATIC_EXPANSIONS not in url_suffix: - logger.exception( + if _PROBLEMATIC_EXPANSIONS in url_suffix: + logger.warning( + f"Replacing {_PROBLEMATIC_EXPANSIONS} with {_REPLACEMENT_EXPANSIONS}" + " and trying again." + ) + url_suffix = url_suffix.replace( + _PROBLEMATIC_EXPANSIONS, + _REPLACEMENT_EXPANSIONS, + ) + continue + if ( + raw_response.status_code == 500 + and limit > _MINIMUM_PAGINATION_LIMIT + ): + new_limit = limit // 2 + logger.warning( f"Error in confluence call to {url_suffix} \n" f"Raw Response Text: {raw_response.text} \n" f"Full Response: {raw_response.__dict__} \n" f"Error: {e} \n" + f"Reducing limit from {limit} to {new_limit} and trying again." ) - raise e + url_suffix = url_suffix.replace( + f"limit={limit}", f"limit={new_limit}" + ) + limit = new_limit + continue - logger.warning( - f"Replacing {_PROBLEMATIC_EXPANSIONS} with {_REPLACEMENT_EXPANSIONS}" - " and trying again." + logger.exception( + f"Error in confluence call to {url_suffix} \n" + f"Raw Response Text: {raw_response.text} \n" + f"Full Response: {raw_response.__dict__} \n" + f"Error: {e} \n" ) - url_suffix = url_suffix.replace( - _PROBLEMATIC_EXPANSIONS, - _REPLACEMENT_EXPANSIONS, - ) - continue + raise e try: next_response = raw_response.json()