refactor(migrations): reduce instance attributes across migration helpers - #835
refactor(migrations): reduce instance attributes across migration helpers#835renansuaris wants to merge 3 commits into
Conversation
|
|
||
| @property | ||
| def _model_cache(self): | ||
| return self._cache.model_cache |
There was a problem hiding this comment.
Unnecessary indirection wrapping attributes in dataclass containers
Low Severity
The FindQuery refactoring introduces _FindQueryState and _FindQueryCache dataclasses plus ~15 property definitions (getters and setters) that add ~120 lines of boilerplate indirection. The attributes still live on the same object conceptually — they're just accessed through an extra layer. This doesn't improve cohesion or testability; it only suppresses the lint warning while making the class harder to read and maintain.
Reviewed by Cursor Bugbot for commit 1c3a4b2. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit 90d8084. Configure here.
| monitor=monitor, | ||
| errors=[], | ||
| dry_run=True, | ||
| ) |
There was a problem hiding this comment.
Dry-run result gains unintended extra success_rate field
Low Severity
The dry-run path now calls _build_monitoring_result, which unconditionally adds a success_rate key to the returned dict. Previously, the dry-run result only contained applied_count, total_migrations, performance_stats, errors, and dry_run. Any consumers or tests asserting on the exact shape of the dry-run result dict will break. The PR states "public behavior should remain unchanged," but this changes the return value contract.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 90d8084. Configure here.


What does this PR do?
Refactors the migration-related classes to reduce the number of instance attributes and satisfy Pylint's
R0902warning ("too-many-instance-attributes"). The changes extract or remove redundant state so each class keeps only the data it actually needs.Why is this change needed?
Some migration classes were accumulating execution state, progress tracking, and metrics in the same object, which made them harder to read, test, and maintain. Reducing instance attributes improves cohesion, simplifies the class responsibilities, and keeps the code within the project's linting rules without changing external behavior.
How was it tested?
Existing tests were run and continue to pass.
Notes for reviewers
This refactor is intentionally minimal and isolated to the instances flagged by Pylint. The public behavior of the migrations should remain unchanged.
Note
Medium Risk
Touches central query execution, RediSearch query building, and model metaclass/index schema logic; behavior is intended to be unchanged but regressions would affect most ORM usage.
Overview
Refactors migration and core model/query classes so execution state, caches, and metadata live in smaller helper objects or properties instead of many loose instance attributes, addressing Pylint
R0902while keeping outward APIs the same.In datetime hash migration, redundant resume/legacy counters (
enable_resume,_processed_keys) are removed, and hash scanning/conversion is moved into_collect_hash_keys,_normalize_hash_data, and_process_hash_keyused by_process_hash_model.DataMigrator.run_migrations_with_monitoringnow builds and logs results via_log_pending_migrations,_build_monitoring_result, and_log_monitoring_summaryinstead of inlined dict/print blocks.model.pyis the bulk of the change:FindQuerystores config in_FindQueryStateand memoized pieces in_FindQueryCache(with property shims); RediSearch value resolution andexecute()are split into focused helpers;FieldInfoRedis options andVectorFieldOptionsoptional params are nested behind properties;DefaultMetausesClassVars;ModelMeta.__new__and JSON indexschema_for_typerecursion are decomposed into static/class helpers. A test assertslimit=0still resolves pagination to the default page size (1000).Reviewed by Cursor Bugbot for commit 90d8084. Bugbot is set up for automated code reviews on this repo. Configure here.