Repository navigation
fix: Method for obtaining workflow model ID - #8237
Conversation
| reranker_model_id = default_model_setting.get("model_id") | ||
|
|
||
| if not reranker_model_id: | ||
| raise Exception(_("Model is not allowed to be empty")) |
There was a problem hiding this comment.
Here are the main points to consider:
1. Changed fallback semantics (potential bug)
The diff removes the fallback to the existing reranker_model_id value:
# Before
reranker_model_id = reference_data.get(
"reranker_model_id", reference_data.get("model_id", reranker_model_id)
)
# After
reranker_model_id = reference_data.get("reranker_model_id", reference_data.get("model_id"))If reference_data contains neither key, the new code sets reranker_model_id = None, while the old code kept the previous value. The same applies to the default_model_setting block:
# Before
reranker_model_id = default_model_setting.get("model_id", reranker_model_id)
# After
reranker_model_id = default_model_setting.get("model_id")This can introduce an unexpected Exception(_("Model is not allowed to be empty")) in cases that previously worked.
Check whether this is intentional. If you want to preserve the previous value when the new dict is incomplete, restore the fallback argument:
reranker_model_id = reference_data.get("reranker_model_id", reference_data.get("model_id", reranker_model_id))2. Existing issue: unsafe .get() on default_model_setting
default_model_setting = workflow_params.get("default_model_setting").get("RERANKER") or {}If workflow_params has no "default_model_setting" key, .get() returns None, and calling .get("RERANKER") on None raises AttributeError. Make it safer:
default_model_setting = (workflow_params.get("default_model_setting") or {}).get("RERANKER") or {}Or add an explicit isinstance check.
3. Optimization / readability
No performance issues are obvious. The logic is simple.
One minor clarity improvement: use a default fallback explicitly where a missing key should mean “keep current value”:
reranker_model_id = reference_data.get("reranker_model_id", reference_data.get("model_id", reranker_model_id))This makes the intent clear and prevents accidental nullification of an already valid model ID.
| model_id = default_model_setting.get("model_id") | ||
| model_params_setting = default_model_setting.get("model_params_setting") | ||
|
|
||
| if not model_id: |
There was a problem hiding this comment.
Review of the diff
1. Behavior change: silent loss of the fallback model_id (main issue)
# before
model_id = reference_data.get("model_id", model_id)
# after
model_id = reference_data.get("model_id")dict.get(key) returns None when the key is absent, so the previous value of model_id (presumably resolved from model_id_reference / earlier logic) is now discarded. The same applies to the default_model_setting branch.
Consequences:
- If
reference_dataexists but simply doesn't contain"model_id", you now wipe out a validmodel_idand fall intoif not model_id, which likely raises an error or falls back to a default unexpectedly. - This is a subtle, easy-to-miss regression. If the intent was "allow the reference to explicitly override with
null", that should be documented; otherwise keep the, model_iddefault.
If you do want to distinguish "key missing" from "key present but None", be explicit:
if "model_id" in reference_data and reference_data["model_id"] is not None:
model_id = reference_data["model_id"]2. model_params_setting is overwritten unconditionally
model_params_setting = reference_data.get("model_params_setting")If the key is absent, this sets model_params_setting to None, potentially clobbering a previously configured value (same problem as above). Guard it:
if "model_params_setting" in reference_data:
model_params_setting = reference_data["model_params_setting"]or only assign when truthy, depending on whether empty dict is meaningful.
3. AttributeError risk in the default branch
default_model_setting = workflow_params.get("default_model_setting").get("LLM") or {}If "default_model_setting" is missing or explicitly None, .get("LLM") raises AttributeError. Use:
default_model_setting = (workflow_params.get("default_model_setting") or {}).get("LLM") or {}Also workflow_params.get("default_model_setting") is evaluated twice — minor, but you can factor it.
4. Type safety
reference_data.get("model_id") / default_model_setting.get("model_id") are not validated. If these can be non-strings (int, dict, etc.), if not model_id won't catch it and downstream code may break. Consider validating type/format here.
5. Duplicated assignment logic
Both branches do the same "override model_id and model_params_setting" pattern. Consider extracting a small helper to keep the semantics identical and avoid future divergence (as just happened with the two .get() calls being changed inconsistently relative to intent).
6. Minor: elif
If model_id_type cannot be both "reference"-like and "default", using elif would signal exclusivity and avoid double work / double overrides.
7. Minor: reference slicing
model_id_reference[1:] assumes the first character is always a prefix marker. If model_id_reference can be empty or have a different format, add validation before slicing.
Bottom line: The core change (dropping the model_id default) is likely a bug unless intentionally allowing None to reset the value. The default_model_setting line also has a latent AttributeError. Both should be fixed or at least clearly justified.
| model_id = default_model_setting.get("model_id") | ||
| model_params_setting = default_model_setting.get("model_params_setting") | ||
|
|
||
| if not model_id: |
There was a problem hiding this comment.
Main issue: behavior change (likely bug)
Changing:
model_id = reference_data.get("model_id", model_id)to:
model_id = reference_data.get("model_id")means that if reference_data is a dict but does not contain "model_id", the previously computed model_id is now overwritten with None.
The same issue applies to:
model_id = default_model_setting.get("model_id")Impact:
- A valid
model_idfrom an earlier step can be discarded. - The later
if not model_id:branch may be triggered incorrectly. - This can cause fallback/default resolution, validation failure, or unexpected
Nonepropagation. - This is not a pure refactor; it changes runtime semantics.
If the intent is “only override when the key exists”, use:
if "model_id" in reference_data:
model_id = reference_data["model_id"]or, to preserve the old behavior explicitly:
model_id = reference_data.get("model_id", model_id)If the intent is “ignore explicit None”, use:
if reference_data.get("model_id") is not None:
model_id = reference_data["model_id"]Related issue: model_params_setting
model_params_setting still uses:
model_params_setting = reference_data.get("model_params_setting")So it will also be reset to None when reference_data exists but does not contain that key. If that is not intended, guard it similarly.
Additional potential issue
This line can raise AttributeError:
default_model_setting = workflow_params.get("default_model_setting").get("TTI") or {}If "default_model_setting" is missing or None, .get("TTI") is called on None. Prefer:
default_model_setting = (
(workflow_params.get("default_model_setting") or {}).get("TTI") or {}
)And validate it is a dict before calling .get on it.
Suggested safer version
if isinstance(reference_data, dict):
if "model_id" in reference_data:
model_id = reference_data["model_id"]
if "model_params_setting" in reference_data:
model_params_setting = reference_data["model_params_setting"]
if model_id_type == "default":
default_model_setting = (
(workflow_params.get("default_model_setting") or {}).get("TTI") or {}
)
if isinstance(default_model_setting, dict):
if "model_id" in default_model_setting:
model_id = default_model_setting["model_id"]
if "model_params_setting" in default_model_setting:
model_params_setting = default_model_setting["model_params_setting"]Recommendation
Treat the diff as a behavioral change. If it was intended to make reference_data and default_model_setting authoritative, document it and add tests for:
- key present with a valid value,
- key present with
None, - key absent,
reference_dataempty or non-dict,default_model_settingmissing orNone.
fix: Method for obtaining workflow model ID