Skip to content

fix(cli): restore fallback for unknown kernel language/type in kernels_pull#1091

Merged
stevemessick merged 1 commit into
Kaggle:mainfrom
sridipbasu:fix/kernels-pull-fallback
Jul 7, 2026
Merged

fix(cli): restore fallback for unknown kernel language/type in kernels_pull#1091
stevemessick merged 1 commit into
Kaggle:mainfrom
sridipbasu:fix/kernels-pull-fallback

Conversation

@sridipbasu

Copy link
Copy Markdown
Contributor

Summary

This fixes a bug in kernels_pull where the existing fallback for unknown kernel language/type combinations was never reached.

If the language/type doesn't match one of the known extension mappings, extension remains None. The code then attempts to build the filename using:

file_name = blob.slug + extension

which raises a TypeError before the fallback logic can execute.

Fix

Instead of concatenating immediately, the code now checks whether an extension was resolved first. If not, it allows the existing fallback to handle the case and use script.py.

This doesn't change the behavior for any of the currently supported language/type mappings.

Tests

Added regression tests covering:

  • unknown language
  • empty language
  • empty kernel type
  • unknown kernel type

Also verified that existing mappings continue to work correctly for supported kernel types.

Validation

  • pytest tests/unit
  • black --check .
  • mypy src/kaggle tests

Comment thread tests/unit/test_kernels_pull.py Outdated

# Verify file write
mock_open_file.assert_called_once_with("/tmp/dummy/my-slug.py", "w", encoding="utf-8")
mock_open_file.assert_called_once_with(os.path.join("/tmp/dummy", "my-slug.py"), "w", encoding="utf-8")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand why one slash was changed to use join instead but two others left in place.

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.

Done, I've reverted the existing path assertions back to their original form to keep this PR focused on the fallback fix.

Comment thread tests/unit/test_kernels_pull.py Outdated
@patch("os.path.isfile", return_value=False)
@patch("builtins.open", new_callable=mock_open)
@patch.object(KaggleApi, "build_kaggle_client")
def test_kernels_pull_supported_julia_script(self, mock_client, mock_open_file, mock_isfile, mock_exists):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

julia is no longer supported, but we haven't cleaned up all the references yet.

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.

Fixed. I've removed the Julia test along with other duplicate supported language tests to refine the PR's scope.

@stevemessick

Copy link
Copy Markdown
Contributor

/gcbrun

@sridipbasu sridipbasu force-pushed the fix/kernels-pull-fallback branch from 355963c to 4ef4aea Compare July 7, 2026 15:08
@stevemessick

Copy link
Copy Markdown
Contributor

/gcbrun

@stevemessick stevemessick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@stevemessick stevemessick merged commit 85b39ac into Kaggle:main Jul 7, 2026
12 checks passed
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.

2 participants