-
Notifications
You must be signed in to change notification settings - Fork 16.9k
Standardize error handling in CLI connection import #64498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bb4a044
08b39ce
b82de8d
444c52e
1ad233b
f235093
f1d8663
6cad370
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -411,26 +411,38 @@ def _import_helper(file_path: str, overwrite: bool) -> None: | |||||||
| :param overwrite: Whether to skip or overwrite on collision. | ||||||||
| """ | ||||||||
| connections_dict = load_connections_dict(file_path) | ||||||||
| suc_count = fail_count = 0 | ||||||||
| with create_session() as session: | ||||||||
| for conn_id, conn in connections_dict.items(): | ||||||||
| try: | ||||||||
| helpers.validate_key(conn_id, max_length=200) | ||||||||
| except Exception as e: | ||||||||
| print(f"Could not import connection. {e}") | ||||||||
|
||||||||
| fail_count += 1 | ||||||||
| continue | ||||||||
|
|
||||||||
| existing_conn_id = session.scalar(select(Connection.id).where(Connection.conn_id == conn_id)) | ||||||||
| if existing_conn_id is not None: | ||||||||
| if not overwrite: | ||||||||
| print(f"Could not import connection {conn_id}: connection already exists.") | ||||||||
| fail_count += 1 | ||||||||
| continue | ||||||||
|
|
||||||||
| # The conn_ids match, but the PK of the new entry must also be the same as the old | ||||||||
| conn.id = existing_conn_id | ||||||||
|
|
||||||||
| session.merge(conn) | ||||||||
| session.commit() | ||||||||
| print(f"Imported connection {conn_id}") | ||||||||
| try: | ||||||||
| session.merge(conn) | ||||||||
| session.commit() | ||||||||
| except Exception as e: | ||||||||
| print(f"Connection import failed for {conn_id}: {e!r}") | ||||||||
|
||||||||
| session.rollback() | ||||||||
| fail_count += 1 | ||||||||
| else: | ||||||||
| suc_count += 1 | ||||||||
|
||||||||
| suc_count += 1 | |
| suc_count += 1 | |
| print(f"Imported connection {conn_id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suc_countis an unclear abbreviation. Rename to something explicit likesuccess_count(and keepfail_countasfailure_countfor symmetry) to improve readability.