Repository navigation
fix(kernels): keep kernels pull from overwriting another kernel's code file - #1242
Merged
stevemessick merged 1 commit intoNov 12, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While looking at the
kaggle kernels pullflow, I found that pulling a kernel into a folder that already holds a different kernel'skernel-metadata.jsonoverwrites that kernel's local code file.For example, with a folder containing
kernel-metadata.jsonforowner/kernel-a(code_file: kernel-a.ipynb), running:writes the source of
kernel-bintokernel-a.ipynb. Any local edits tokernel-a.ipynbare lost, nokernel-bfile is created, and the command exits with code0.The issue was that
kernels_pull()reuses thecode_filefrom anykernel-metadata.jsonit finds in the target folder, without checking that the metadataidbelongs to the kernel being pulled. This reuse was meant for pulling the same kernel again.Fix
I changed the metadata fallback to reuse
code_fileonly when the metadataidmatches the requested owner and slug. The comparison is case-insensitive and ignores the version.When the IDs do not match, the existing default file name (
<slug>.<ext>) is used.Pulling the same kernel again still reuses its
code_fileas before. Thekernel=Nonepath that reads the kernel ID from the local metadata is unchanged. No changes were made to the API request or the Python library method signature.Tests
Added
test_kernels_pull_code_file_only_reused_for_same_kernelusing a real temporary folder. It covers:<slug>.pyand the existing local file is left untouched.id: the existingcode_fileis reused.The test fails with the old implementation and passes with this fix.
Ran:
Results:
The warning is an existing unrelated
DeprecationWarning.Also ran the Black check, which passed.
I also verified the behavior against the live API. Pulling one of my kernels into a folder holding another kernel's metadata now creates a new file and leaves the existing one unchanged. Pulling the same kernel still writes to the
code_filefrom the metadata.This change only affects the local file name chosen during
kernels pull. It does not change the API requests, the Python library API, or any waiting and polling flow.