Skip to content

[BUG]: Multiple gateway import failing with unique constraint error for resources #2352

@ramcysiddique

Description

@ramcysiddique

This is happening for moody's mcp server.First time gateway adding is working fine.But on re-adding the gateway, we are getting duplicate resource issue.
Please see the logs below.

sqlalchemy.exc.PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "uq_team_owner_uri_resource"
DETAIL:  Key (team_id, owner_email, uri)=(55d6f8381bd24b46966a763b18bc7bfb, admin@example.com, file://moodys-legal-disclaimer/) already exists.

[SQL: INSERT INTO resources (id, uri, name, description, mime_type, size, uri_template, created_at, updated_at, enabled, tags, created_by, created_from_ip, created_via, created_user_agent, modified_by, modified_from_ip, modified_via, modified_user_agent, i ... 7272 characters truncated ... (binary_content__12)s, %(gateway_id__12)s, %(team_id__12)s, %(owner_email__12)s, %(visibility__12)s)]
[parameters: {'created_at__0': datetime.datetime(2026, 1, 23, 13, 7, 2, 183518, tzinfo=datetime.timezone.utc), 'modified_from_ip__0': None, 'modified_via__0': None, 'created_via__0': 'federation', 'owner_email__0': 'admin@example.com', 'created_by__0': 'admin@example.com', 'federation_source__0': 'moodys1', 'team_id__0': '55d6f8381bd24b46966a763b18bc7bfb', 'text_content__0': '', 'id__0': 'e41315f0e96d4c518123aeb9d9de24ad', 'uri_template__0': None, 'tags__0': '[]', 'visibility__0': 'public', 'uri__0': 'file://moodys-legal-disclaimer/', 'import_batch_id__0': None, 'enabled__0': True, 'created_from_ip__0': '127.0.0.1', 'version__0': 1, 'description__0': 'Legal disclaimers for the Screening Agent MCP server and the content it uses.', 'mime_type__0': 'text/plain', 'modified_by__0': None, 'modified_user_agent__0': None, 'size__0': 0, 'binary_content__0': <psycopg2.extensions.Binary object at 0x1237b9320>, 'name__0': 'legalDisclaimers', 'gateway_id__0': '764c086021324185b8509b96803920b9', 'created_user_agent__0': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36', 'updated_at__0': datetime.datetime(2026, 1, 23, 13, 7, 2, 183520, tzinfo=datetime.timezone.utc), 'created_at__1': datetime.datetime(2026, 1, 23, 13, 7, 2, 183530, tzinfo=datetime.timezone.utc), 'modified_from_ip__1': None, 'modified_via__1': None, 'created_via__1': 'federation', 'owner_email__1': 'admin@example.com', 'created_by__1': 'admin@example.com', 'federation_source__1': 'moodys1', 'team_id__1': '55d6f8381bd24b46966a763b18bc7bfb', 'text_content__1': '', 'id__1': 'ba703b87820b477bab91a03fcf6c5682', 'uri_template__1': None, 'tags__1': '[]', 'visibility__1': 'public', 'uri__1': 'grid-entities://2262f9db-dfe4-4446-a7c3-65ea8647fbf2.json', 'import_batch_id__1': None, 'enabled__1': True, 'created_from_ip__1': '127.0.0.1', 'version__1': 1, 'description__1': 'Grid entity ground truth data for task 2262f9db-dfe4-4446-a7c3-65ea8647fbf2', 'mime_type__1': 'text/plain', 'modified_by__1': None, 'modified_user_agent__1': None ... 264 parameters truncated ... 'federation_source__11': 'moodys1', 'team_id__11': '55d6f8381bd24b46966a763b18bc7bfb', 'text_content__11': '', 'id__11': '5680f13fe4f74806b53652ceb4b9b4be', 'uri_template__11': None, 'tags__11': '[]', 'visibility__11': 'public', 'uri__11': 'grid-entities://ff0279f5-1948-4ae4-99b8-d9c3ef88d0d1.json', 'import_batch_id__11': None, 'enabled__11': True, 'created_from_ip__11': '127.0.0.1', 'version__11': 1, 'description__11': 'Grid entity ground truth data for task ff0279f5-1948-4ae4-99b8-d9c3ef88d0d1', 'mime_type__11': 'text/plain', 'modified_by__11': None, 'modified_user_agent__11': None, 'size__11': 0, 'binary_content__11': <psycopg2.extensions.Binary object at 0x12460f330>, 'name__11': 'gridEntityGroundTruth', 'gateway_id__11': '764c086021324185b8509b96803920b9', 'created_user_agent__11': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36', 'updated_at__11': datetime.datetime(2026, 1, 23, 13, 7, 2, 183626, tzinfo=datetime.timezone.utc), 'created_at__12': datetime.datetime(2026, 1, 23, 13, 7, 2, 183634, tzinfo=datetime.timezone.utc), 'modified_from_ip__12': None, 'modified_via__12': None, 'created_via__12': 'federation', 'owner_email__12': 'admin@example.com', 'created_by__12': 'admin@example.com', 'federation_source__12': 'moodys1', 'team_id__12': '55d6f8381bd24b46966a763b18bc7bfb', 'text_content__12': '', 'id__12': 'a562d8b5d9334500aa7ecd7b541a4011', 'uri_template__12': 'grid-entities://{taskId}.json', 'tags__12': '[]', 'visibility__12': 'public', 'uri__12': 'grid-entities://{taskId}.json', 'import_batch_id__12': None, 'enabled__12': True, 'created_from_ip__12': '127.0.0.1', 'version__12': 1, 'description__12': 'Get a record of the entities screened by the Screening Agent by task ID. This resource returns full entity details for each match screened.', 'mime_type__12': 'text/plain', 'modified_by__12': None, 'modified_user_agent__12': None, 'size__12': 0, 'binary_content__12': <psycopg2.extensions.Binary object at 0x12460ed90>, 'name__12': 'gridEntityGroundTruth', 'gateway_id__12': '764c086021324185b8509b96803920b9', 'created_user_agent__12': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36', 'updated_at__12': datetime.datetime(2026, 1, 23, 13, 7, 2, 183635, tzinfo=datetime.timezone.utc)}]
(Background on this error at: https://sqlalche.me/e/20/gkpj) (Background on this error at: https://sqlalche.me/e/20/7s2a)
2026-01-23 18:37:02,202 - mcpgateway.utils.error_formatter - ERROR - Database error: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "uq_team_owner_uri_resource"
DETAIL:  Key (team_id, owner_email, uri)=(55d6f8381bd24b46966a763b18bc7bfb, admin@example.com, file://moodys-legal-disclaimer/) already exists.

[SQL: INSERT INTO resources (id, uri, name, description, mime_type, size, uri_template, created_at, updated_at, enabled, tags, created_by, created_from_ip, created_via, created_user_agent, modified_by, modified_from_ip, modified_via, modified_user_agent, i ... 7272 characters truncated ... (binary_content__12)s, %(gateway_id__12)s, %(team_id__12)s, %(owner_email__12)s, %(visibility__12)s)]
[parameters: {'created_at__0': datetime.datetime(2026, 1, 23, 13, 7, 2, 183518, tzinfo=datetime.timezone.utc), 'modified_from_ip__0': None, 'modified_via__0': None, 'created_via__0': 'federation', 'owner_email__0': 'admin@example.com', 'created_by__0': 'admin@example.com', 'federation_source__0': 'moodys1', 'team_id__0': '55d6f8381bd24b46966a763b18bc7bfb', 'text_content__0': '', 'id__0': 'e41315f0e96d4c518123aeb9d9de24ad', 'uri_template__0': None, 'tags__0': '[]', 'visibility__0': 'public', 'uri__0': 'file://moodys-legal-disclaimer/', 'import_batch_id__0': None, 'enabled__0': True, 'created_from_ip__0': '127.0.0.1', 'version__0': 1, 'description__0': 'Legal disclaimers for the Screening Agent MCP server and the content it uses.', 'mime_type__0': 'text/plain', 'modified_by__0': None, 'modified_user_agent__0': None, 'size__0': 0, 'binary_content__0': <psycopg2.extensions.Binary object at 0x1237b9320>, 'name__0': 'legalDisclaimers', 'gateway_id__0': '764c086021324185b8509b96803920b9', 'created_user_agent__0': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36', 'updated_at__0': datetime.datetime(2026, 1, 23, 13, 7, 2, 183520, tzinfo=datetime.timezone.utc), 'created_at__1': datetime.datetime(2026, 1, 23, 13, 7, 2, 183530, tzinfo=datetime.timezone.utc), 'modified_from_ip__1': None, 'modified_via__1': None, 'created_via__1': 'federation', 'owner_email__1': 'admin@example.com', 'created_by__1': 'admin@example.com', 'federation_source__1': 'moodys1', 'team_id__1': '55d6f8381bd24b46966a763b18bc7bfb', 'text_content__1': '', 'id__1': 'ba703b87820b477bab91a03fcf6c5682', 'uri_template__1': None, 'tags__1': '[]', 'visibility__1': 'public', 'uri__1': 'grid-entities://2262f9db-dfe4-4446-a7c3-65ea8647fbf2.json', 'import_batch_id__1': None, 'enabled__1': True, 'created_from_ip__1': '127.0.0.1', 'version__1': 1, 'description__1': 'Grid entity ground truth data for task 2262f9db-dfe4-4446-a7c3-65ea8647fbf2', 'mime_type__1': 'text/plain', 'modified_by__1': None, 'modified_user_agent__1': None ... 264 parameters truncated ... 'federation_source__11': 'moodys1', 'team_id__11': '55d6f8381bd24b46966a763b18bc7bfb', 'text_content__11': '', 'id__11': '5680f13fe4f74806b53652ceb4b9b4be', 'uri_template__11': None, 'tags__11': '[]', 'visibility__11': 'public', 'uri__11': 'grid-entities://ff0279f5-1948-4ae4-99b8-d9c3ef88d0d1.json', 'import_batch_id__11': None, 'enabled__11': True, 'created_from_ip__11': '127.0.0.1', 'version__11': 1, 'description__11': 'Grid entity ground truth data for task ff0279f5-1948-4ae4-99b8-d9c3ef88d0d1', 'mime_type__11': 'text/plain', 'modified_by__11': None, 'modified_user_agent__11': None, 'size__11': 0, 'binary_content__11': <psycopg2.extensions.Binary object at 0x12460f330>, 'name__11': 'gridEntityGroundTruth', 'gateway_id__11': '764c086021324185b8509b96803920b9', 'created_user_agent__11': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36', 'updated_at__11': datetime.datetime(2026, 1, 23, 13, 7, 2, 183626, tzinfo=datetime.timezone.utc), 'created_at__12': datetime.datetime(2026, 1, 23, 13, 7, 2, 183634, tzinfo=datetime.timezone.utc), 'modified_from_ip__12': None, 'modified_via__12': None, 'created_via__12': 'federation', 'owner_email__12': 'admin@example.com', 'created_by__12': 'admin@example.com', 'federation_source__12': 'moodys1', 'team_id__12': '55d6f8381bd24b46966a763b18bc7bfb', 'text_content__12': '', 'id__12': 'a562d8b5d9334500aa7ecd7b541a4011', 'uri_template__12': 'grid-entities://{taskId}.json', 'tags__12': '[]', 'visibility__12': 'public', 'uri__12': 'grid-entities://{taskId}.json', 'import_batch_id__12': None, 'enabled__12': True, 'created_from_ip__12': '127.0.0.1', 'version__12': 1, 'description__12': 'Get a record of the entities screened by the Screening Agent by task ID. This resource returns full entity details for each match screened.', 'mime_type__12': 'text/plain', 'modified_by__12': None, 'modified_user_agent__12': None, 'size__12': 0, 'binary_content__12': <psycopg2.extensions.Binary object at 0x12460ed90>, 'name__12': 'gridEntityGroundTruth', 'gateway_id__12': '764c086021324185b8509b96803920b9', 'created_user_agent__12': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36', 'updated_at__12': datetime.datetime(2026, 1, 23, 13, 7, 2, 183635, tzinfo=datetime.timezone.utc)}]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions