jason810496 commented on code in PR #44322:
URL: https://github.com/apache/airflow/pull/44322#discussion_r1857005425


##########
tests/api_fastapi/core_api/routes/public/test_connections.py:
##########
@@ -235,9 +235,7 @@ def test_post_should_respond_already_exist(self, 
test_client, body):
         # Another request
         response = test_client.post("/public/connections/", json=body)
         assert response.status_code == 409
-        assert response.json() == {
-            "detail": f"Connection with connection_id: `{TEST_CONN_ID}` 
already exists",
-        }
+        assert response.json() == {"detail": "Unique constraint violation"}

Review Comment:
   Here are the `Pool` and `Connection` error details currently being handled. 
I used `pprint(exc.__dict__)` to display all possible error details that can be 
utilized. However, it seems quite challenging to parse generic information from 
the database error exceptions.
   
   
   ### Pool
   
   #### SQLite
   ```
   IntegrityError('(sqlite3.IntegrityError) UNIQUE constraint failed: 
slot_pool.pool')
   {'code': 'gkpj',
    'connection_invalidated': False,
    'detail': [],
    'hide_parameters': False,
    'ismulti': False,
    'orig': IntegrityError('UNIQUE constraint failed: slot_pool.pool'),
    'params': ('my_pool', 11, None, 0),
    'statement': 'INSERT INTO slot_pool (pool, slots, description, '
                 'include_deferred) VALUES (?, ?, ?, ?)'}
   ```
   #### Postgres
   ```
   IntegrityError('(psycopg2.errors.UniqueViolation) duplicate key value 
violates unique constraint "slot_pool_pool_uq"\nDETAIL:  Key (pool)=(my_pool) 
already exists.\n')
   {'code': 'gkpj',
    'connection_invalidated': False,
    'detail': [],
    'hide_parameters': False,
    'ismulti': False,
    'orig': UniqueViolation('duplicate key value violates unique constraint 
"slot_pool_pool_uq"\nDETAIL:  Key (pool)=(my_pool) already exists.\n'),
    'params': {'description': None,
               'include_deferred': False,
               'pool': 'my_pool',
               'slots': 11},
    'statement': 'INSERT INTO slot_pool (pool, slots, description, '
                 'include_deferred) VALUES (%(pool)s, %(slots)s, 
%(description)s, '
                 '%(include_deferred)s) RETURNING slot_pool.id'}
   ```
   
   #### MySQL
   ```
   IntegrityError('(MySQLdb.IntegrityError) (1062, "Duplicate entry \'my_pool\' 
for key \'slot_pool.slot_pool_pool_uq\'")')
   {'code': 'gkpj',
    'connection_invalidated': False,
    'detail': [],
    'hide_parameters': False,
    'ismulti': False,
    'orig': IntegrityError(1062, "Duplicate entry 'my_pool' for key 
'slot_pool.slot_pool_pool_uq'"),
    'params': ('my_pool', 11, None, 0),
    'statement': 'INSERT INTO slot_pool (pool, slots, description, '
                 'include_deferred) VALUES (%s, %s, %s, %s)'}
    ```
    
    ### Connection
    
   #### SQLite
   ```
   IntegrityError('(sqlite3.IntegrityError) UNIQUE constraint failed: 
connection.conn_id')
   {'code': 'gkpj',
    'connection_invalidated': False,
    'detail': [],
    'hide_parameters': False,
    'ismulti': False,
    'orig': IntegrityError('UNIQUE constraint failed: connection.conn_id'),
    'params': ('test_connection_id',
               'test_type',
               None,
               None,
               None,
               None,
               None,
               None,
               0,
               0,
               None),
    'statement': 'INSERT INTO connection (conn_id, conn_type, description, 
host, '
                 'schema, login, password, port, is_encrypted, '
                 'is_extra_encrypted, extra) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 
'
                 '?, ?)'}
   ```
   #### Postgres
   ```
   IntegrityError('(psycopg2.errors.UniqueViolation) duplicate key value 
violates unique constraint "connection_conn_id_uq"\nDETAIL:  Key 
(conn_id)=(test_connection_id) already exists.\n')
   {'code': 'gkpj',
    'connection_invalidated': False,
    'detail': [],
    'hide_parameters': False,
    'ismulti': False,
    'orig': UniqueViolation('duplicate key value violates unique constraint 
"connection_conn_id_uq"\nDETAIL:  Key (conn_id)=(test_connection_id) already 
exists.\n'),
    'params': {'conn_id': 'test_connection_id',
               'conn_type': 'test_type',
               'description': None,
               'extra': None,
               'host': None,
               'is_encrypted': False,
               'is_extra_encrypted': False,
               'login': None,
               'password': None,
               'port': None,
               'schema': None},
    'statement': 'INSERT INTO connection (conn_id, conn_type, description, 
host, '
                 'schema, login, password, port, is_encrypted, '
                 'is_extra_encrypted, extra) VALUES (%(conn_id)s, 
%(conn_type)s, '
                 '%(description)s, %(host)s, %(schema)s, %(login)s, 
%(password)s, '
                 '%(port)s, %(is_encrypted)s, %(is_extra_encrypted)s, 
%(extra)s) '
                 'RETURNING connection.id'}
   ```
   
   #### MySQL
   ```
   IntegrityError('(MySQLdb.IntegrityError) (1062, "Duplicate entry 
\'test_connection_id\' for key \'connection.connection_conn_id_uq\'")')
   {'code': 'gkpj',
    'connection_invalidated': False,
    'detail': [],
    'hide_parameters': False,
    'ismulti': False,
    'orig': IntegrityError(1062, "Duplicate entry 'test_connection_id' for key 
'connection.connection_conn_id_uq'"),
    'params': ('test_connection_id',
               'test_type',
               None,
               None,
               None,
               None,
               None,
               None,
               0,
               0,
               None),
    'statement': 'INSERT INTO connection (conn_id, conn_type, description, 
host, '
                 '`schema`, login, password, port, is_encrypted, '
                 'is_extra_encrypted, extra) VALUES (%s, %s, %s, %s, %s, %s, 
%s, '
                 '%s, %s, %s, %s)'}
    ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to