Kaggle / kaggle-api

Official Kaggle API
Apache License 2.0
6.16k stars 1.08k forks source link

split_dataset_string breaks kaggle_api_extended #539

Closed yellowdolphin closed 8 months ago

yellowdolphin commented 8 months ago

ValueError: not enough values to unpack (expected 3, got 2)

How to reproduce/Test:

(1) Ensure the KaggleApi instance has CONFIG_NAME_USER and version == '1.6.2' (2) Call API functions dataset_list_files or dataset_download_files with a bare dataset name.

For instance

from kaggle.api.kaggle_api_extended import KaggleApi

api = KaggleApi()
api.authenticate()
api.dataset_list_files('my_dataset')

Cause:

kaggle_api_extended.split_dataset_string returns a tuple of 2 if dataset contains no '/'.

The method is called by two other methods in class KaggleApi (dataset_list_files and dataset_download_files), both of which break trying to unpack a tuple of 3:

        owner_slug, dataset_slug, dataset_version_number = self.split_dataset_string(
            dataset)

Fix:

Might be to return None as 3rd value. This happens also when dataset contains a single '/'.

Also:

With this fix, split_dataset_string could be called also in dataset_download_file to get rid of the redundant code there.

(I'm not familiar with swagger, so I will not make a pull request)

jplotts commented 8 months ago

Hi @yellowdolphin - dataset_list_files requires a / because the dataset is referred to by username/dataset_name . The CONFIG_NAME_USER refers to the current user but isn't assumed to be the owner of the dataset, since you may want to pull data from other users.