potiuk commented on a change in pull request #18161:
URL: https://github.com/apache/airflow/pull/18161#discussion_r706588381



##########
File path: airflow/www/views.py
##########
@@ -3320,28 +3320,38 @@ def action_mulduplicate(self, connections, 
session=None):
             else:
                 new_conn_id += '_copy1'
 
-            dup_conn = Connection(
-                new_conn_id,
-                selected_conn.conn_type,
-                selected_conn.description,
-                selected_conn.host,
-                selected_conn.login,
-                selected_conn.password,
-                selected_conn.schema,
-                selected_conn.port,
-                selected_conn.extra,
-            )
-
-            try:
-                session.add(dup_conn)
-                session.commit()
-                flash(f"Connection {new_conn_id} added successfully.", 
"success")
-            except IntegrityError:
+            # Before creating a new connection
+            # Query to see if connection exists.
+            connection = session.query(Connection).filter(Connection.conn_id 
== new_conn_id).one_or_none()
+            if connection is not None:
                 flash(
-                    f"Connection {new_conn_id} can't be added. Integrity 
error, probably unique constraint.",
+                    f"Connection {new_conn_id} can't be added because it 
lready exists",

Review comment:
       How about adding a small loop and trying to add further _1 , _2 , _3 
....... suffix up to, say, 10 times ? 




-- 
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