Skip to content

fix: Method for obtaining workflow model ID - #8237

Merged
shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_model
Dec 1, 2026
Merged

shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_model

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: Method for obtaining workflow model ID

reranker_model_id = default_model_setting.get("model_id")

if not reranker_model_id:
raise Exception(_("Model is not allowed to be empty"))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_data exists but simply doesn't contain "model_id", you now wipe out a valid model_id and fall into if 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_id default.

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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id from 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 None propagation.
  • 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_data empty or non-dict,
  • default_model_setting missing or None.

@shaohuzhang1
shaohuzhang1 merged commit 3d26b1d into v3 Dec 1, 2026
3 of 4 checks passed
@shaohuzhang1
shaohuzhang1 deleted the pr@v3@fix_model branch December 1, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant