Improve code quality - base class, exceptions, imports, tests#122
Merged
Conversation
Summary: - Add BaseMilvusClient base class, eliminating ~180 lines of duplicated code - Add safe_int() utility for robust null/string handling - Fix all 93 'raise Exception' → RuntimeError/ValueError with exception chaining - Fix all bare 'except:' → 'except Exception:' across core and test modules - Fix fake implementations (show_loading_progress, get_index_build_progress) - Fix insert/upsert list-of-lists field misalignment with auto_id fields - Remove duplicate OutputFormatter class and double formatter assignment - Replace wildcard imports with explicit side-effect imports - Replace sys.path.append hack with relative imports - Add try/except ImportError for dual-mode import compatibility - Ensure list_user_roles always returns list - Update README/TESTING.md project structure - Fix 6 flaky unit tests (API response format, env assumptions) - Clean up stale Dockerfile.test, add .cursor/.kiro/test.env to .gitignore
nameczz
approved these changes
Mar 30, 2026
Collaborator
|
@cloudsmithy Thanks for the PR! It looks great, but merging is currently blocked because your commits need verified signatures. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Code quality refactoring that reduces ~400 lines while fixing several bugs and improving maintainability.
Changes
Architecture
BaseMilvusClientbase class — eliminates duplicated__init__+_get_client()across 10 client modulessafe_int()utility — eliminates repeated null/string checking forrow_countOutputFormatterclass fromCliClient.py(was defined in bothCliClient.pyandOutputFormatter.py)Bug Fixes
show_loading_progresswas returning hardcoded{"loading_progress": "100%"}— now calls realget_load_stateAPIget_index_build_progresswas returning hardcoded{"progress": "100%", "state": "Finished"}— now calls realdescribe_indexAPIinsert/upsertlist-of-lists conversion had field misalignment when collection hasauto_id— now correctly skips auto_id fieldslist_user_rolescould return tuple instead of list — now always returns listCliClient.__init__assignedself.formattertwiceException Handling
raise Exception(f"...{str(e)}")withraise RuntimeError/ValueError(f"...{e}") from eexcept:→except Exception:(was catching KeyboardInterrupt)ConnectionErrorinBaseMilvusClient._get_client()ValueErrorfor business logic validation (missing partition, user not found, etc.)Import Cleanup
from .xxx import *with explicit side-effect imports in entry pointssys.path.appendhack with relative imports in 7 script filestry/except ImportErrorpattern for dual-mode compatibility (package import + direct run)import sys/import osfrom 7 filesHousekeeping
Dockerfile.test(single line, unused).DS_Storefrom git tracking.cursor/,.kiro/,test.envto.gitignoreREADME.mdproject structure to match actual filenamestest.envfrom repo (contained credentials)Test Fixes
test_describe_database— assert correct API response key (namenotdatabase_name)test_get_partition_stats— use_defaultpartition to avoid ordering dependencytest_list_users— don't hardcodedb_admin(Zilliz Cloud specific)test_get_index_build_progress— match real API response formattest_grant_and_revoke_privilegeexcept:in test filesStats
40 files changed, 496 insertions(+), 895 deletions(-)
Testing
102 unit tests passing against local Milvus standalone.