Skip to content

fix(core/singletask): guard BASE_MODEL_URL assignment against None in…#575

Open
g-k-s-03 wants to merge 2 commits into
kubeedge:mainfrom
g-k-s-03:fix/singletask-base-model-url-none
Open

fix(core/singletask): guard BASE_MODEL_URL assignment against None in…#575
g-k-s-03 wants to merge 2 commits into
kubeedge:mainfrom
g-k-s-03:fix/singletask-base-model-url-none

Conversation

@g-k-s-03

@g-k-s-03 g-k-s-03 commented Jul 2, 2026

Copy link
Copy Markdown

Description

SingleTaskLearning._train() unconditionally assigns
os.environ["BASE_MODEL_URL"] = initial_model, where initial_model
is None when initial_model_url is absent from the algorithm YAML.
This raises TypeError: str expected, not NoneType immediately.

A secondary issue exists in multi-test-case benchmarks: when test
cases run sequentially in the same process via testcase.py, a stale
BASE_MODEL_URL set by a prior test case persists into subsequent
ones that omit initial_model_url, causing the wrong pretrained
checkpoint to be loaded silently.

Fix

Replaced the unconditional assignment with a guarded block:

if initial_model is not None:
    os.environ["BASE_MODEL_URL"] = initial_model
else:
    os.environ.pop("BASE_MODEL_URL", None)

The pop with a default value clears any stale entry from a prior
test case, preventing cross-test-case environment pollution.

Files Changed

  • core/testcasecontroller/algorithm/paradigm/singletask_learning/singletask_learning.py

Fixes #574

…itial_model_url, Issue 574

Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
@kubeedge-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: g-k-s-03
To complete the pull request process, please assign jaypume after the PR has been reviewed.
You can assign the PR to them by writing /assign @jaypume in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 2, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the _train method in singletask_learning.py to conditionally set or remove the BASE_MODEL_URL environment variable depending on whether initial_model is provided. The review feedback suggests a more robust check (if initial_model:) to handle both None and empty string values, preventing potential issues in downstream components that check for the presence of this environment variable.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +120 to +123
if initial_model is not None:
os.environ["BASE_MODEL_URL"] = initial_model
else:
os.environ.pop("BASE_MODEL_URL", None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In Algorithm, self.initial_model_url is initialized as an empty string ("") by default. If initial_model_url is omitted from the configuration, initial_model can be passed as "" rather than None.

Setting os.environ["BASE_MODEL_URL"] = "" can cause issues in downstream components or subprocesses that check for the presence of the environment variable (e.g., "BASE_MODEL_URL" in os.environ).

To make this guard more robust against both None and empty strings, consider checking if initial_model: instead of if initial_model is not None:.

Suggested change
if initial_model is not None:
os.environ["BASE_MODEL_URL"] = initial_model
else:
os.environ.pop("BASE_MODEL_URL", None)
if initial_model:
os.environ["BASE_MODEL_URL"] = initial_model
else:
os.environ.pop("BASE_MODEL_URL", None)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Valid point; updated to if initial_model: to handle both None and empty string cases, since self.initial_model_url defaults to "" in the base class

…pty string

Signed-off-by: g-k-s-03 <govindsingh97704@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(core/singletask): TypeError crash and stale BASE_MODEL_URL when initial_model_url is omitted from YAML

2 participants