Skip to content

Commit ac458a8

Browse files
committed
fix: wizard bug fixes and improvements (#564)
- Filter staged additions from update/rename candidate lists - Cancel staged-add on remove instead of appending to remove_fields - Add _filter_staged_adds helper method - Reflect update_fields in working schema (_apply_staged_changes) - Prevent no-op vector algorithm update when user enters current value
1 parent ef102da commit ac458a8

1 file changed

Lines changed: 53 additions & 4 deletions

File tree

redisvl/migration/wizard.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ def _resolve_index_name(
113113
return indexes[offset]
114114
print("Invalid selection. Please try again.")
115115

116+
@staticmethod
117+
def _filter_staged_adds(
118+
working_schema: Dict[str, Any], staged_add_names: set
119+
) -> Dict[str, Any]:
120+
"""Return a copy of working_schema with staged-add fields removed.
121+
122+
This prevents staged additions from appearing in update/rename
123+
candidate lists.
124+
"""
125+
import copy
126+
127+
filtered = copy.deepcopy(working_schema)
128+
filtered["fields"] = [
129+
f for f in filtered["fields"] if f["name"] not in staged_add_names
130+
]
131+
return filtered
132+
133+
116134
def _apply_staged_changes(
117135
self,
118136
source_schema: Dict[str, Any],
@@ -139,6 +157,16 @@ def _apply_staged_changes(
139157
if field["name"] in rename_map:
140158
field["name"] = rename_map[field["name"]]
141159

160+
# Apply updates (reflect attribute changes in working schema)
161+
update_map = {u.name: u for u in changes.update_fields}
162+
for field in working["fields"]:
163+
if field["name"] in update_map:
164+
upd = update_map[field["name"]]
165+
if upd.attrs:
166+
field.setdefault("attrs", {}).update(upd.attrs)
167+
if upd.type:
168+
field["type"] = upd.type
169+
142170
# Apply adds
143171
for added in changes.add_fields:
144172
working["fields"].append(added)
@@ -181,15 +209,36 @@ def _build_patch(
181209
else:
182210
changes.add_fields.append(field)
183211
elif action == "2":
184-
update = self._prompt_update_field(working_schema)
212+
# Filter out staged additions from update candidates
213+
staged_add_names = {f["name"] for f in changes.add_fields}
214+
update_schema = self._filter_staged_adds(
215+
working_schema, staged_add_names
216+
)
217+
update = self._prompt_update_field(update_schema)
185218
if update:
186219
changes.update_fields.append(update)
187220
elif action == "3":
188221
field_name = self._prompt_remove_field(working_schema)
189222
if field_name:
190-
changes.remove_fields.append(field_name)
223+
# If removing a staged-add, cancel the add instead of
224+
# appending to remove_fields
225+
staged_add_names = {f["name"] for f in changes.add_fields}
226+
if field_name in staged_add_names:
227+
changes.add_fields = [
228+
f
229+
for f in changes.add_fields
230+
if f["name"] != field_name
231+
]
232+
print(f"Cancelled staged addition of '{field_name}'.")
233+
else:
234+
changes.remove_fields.append(field_name)
191235
elif action == "4":
192-
field_rename = self._prompt_rename_field(working_schema)
236+
# Filter out staged additions from rename candidates
237+
staged_add_names = {f["name"] for f in changes.add_fields}
238+
rename_schema = self._filter_staged_adds(
239+
working_schema, staged_add_names
240+
)
241+
field_rename = self._prompt_rename_field(rename_schema)
193242
if field_rename:
194243
changes.rename_fields.append(field_rename)
195244
elif action == "5":
@@ -542,7 +591,7 @@ def _prompt_vector_attrs(self, field: Dict[str, Any]) -> Dict[str, Any]:
542591
.upper()
543592
.replace("_", "-") # Normalize SVS_VAMANA to SVS-VAMANA
544593
)
545-
if algo and algo in ("FLAT", "HNSW", "SVS-VAMANA"):
594+
if algo and algo in ("FLAT", "HNSW", "SVS-VAMANA") and algo != current_algo:
546595
attrs["algorithm"] = algo
547596

548597
# Datatype (quantization) - show algorithm-specific options

0 commit comments

Comments
 (0)