We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
regression: fallback if streaming fails is disabled
Causes https://github.com/huggingface/datasets/issues/3185 for example: the fallback should have loaded the dataset in normal mode.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/datasets_preview_backend/config.py`
Content:
```
1 import os
2 
3 from dotenv import load_dotenv
4 
5 from datasets_preview_backend.constants import (
6     DEFAULT_APP_HOSTNAME,
7     DEFAULT_APP_PORT,
8     DEFAULT_ASSETS_DIRECTORY,
9     DEFAULT_DATASETS_ENABLE_PRIVATE,
10     DEFAULT_DATASETS_REVISION,
11     DEFAULT_HF_TOKEN,
12     DEFAULT_LOG_LEVEL,
13     DEFAULT_MAX_AGE_LONG_SECONDS,
14     DEFAULT_MAX_AGE_SHORT_SECONDS,
15     DEFAULT_MONGO_CACHE_DATABASE,
16     DEFAULT_MONGO_QUEUE_DATABASE,
17     DEFAULT_MONGO_URL,
18     DEFAULT_ROWS_MAX_BYTES,
19     DEFAULT_ROWS_MAX_NUMBER,
20     DEFAULT_ROWS_MIN_NUMBER,
21     DEFAULT_WEB_CONCURRENCY,
22 )
23 from datasets_preview_backend.utils import (
24     get_bool_value,
25     get_int_value,
26     get_str_or_none_value,
27     get_str_value,
28 )
29 
30 # Load environment variables defined in .env, if any
31 load_dotenv()
32 
33 APP_HOSTNAME = get_str_value(d=os.environ, key="APP_HOSTNAME", default=DEFAULT_APP_HOSTNAME)
34 APP_PORT = get_int_value(d=os.environ, key="APP_PORT", default=DEFAULT_APP_PORT)
35 ASSETS_DIRECTORY = get_str_or_none_value(d=os.environ, key="ASSETS_DIRECTORY", default=DEFAULT_ASSETS_DIRECTORY)
36 DATASETS_ENABLE_PRIVATE = get_bool_value(
37     d=os.environ, key="DATASETS_ENABLE_PRIVATE", default=DEFAULT_DATASETS_ENABLE_PRIVATE
38 )
39 DATASETS_REVISION = get_str_value(d=os.environ, key="DATASETS_REVISION", default=DEFAULT_DATASETS_REVISION)
40 HF_TOKEN = get_str_or_none_value(d=os.environ, key="HF_TOKEN", default=DEFAULT_HF_TOKEN)
41 LOG_LEVEL = get_str_value(d=os.environ, key="LOG_LEVEL", default=DEFAULT_LOG_LEVEL)
42 MAX_AGE_LONG_SECONDS = get_int_value(d=os.environ, key="MAX_AGE_LONG_SECONDS", default=DEFAULT_MAX_AGE_LONG_SECONDS)
43 MAX_AGE_SHORT_SECONDS = get_int_value(d=os.environ, key="MAX_AGE_SHORT_SECONDS", default=DEFAULT_MAX_AGE_SHORT_SECONDS)
44 MONGO_CACHE_DATABASE = get_str_value(d=os.environ, key="MONGO_CACHE_DATABASE", default=DEFAULT_MONGO_CACHE_DATABASE)
45 MONGO_QUEUE_DATABASE = get_str_value(d=os.environ, key="MONGO_QUEUE_DATABASE", default=DEFAULT_MONGO_QUEUE_DATABASE)
46 MONGO_URL = get_str_value(d=os.environ, key="MONGO_URL", default=DEFAULT_MONGO_URL)
47 WEB_CONCURRENCY = get_int_value(d=os.environ, key="WEB_CONCURRENCY", default=DEFAULT_WEB_CONCURRENCY)
48 
49 # Ensure datasets library uses the expected revision for canonical datasets
50 os.environ["HF_SCRIPTS_VERSION"] = DATASETS_REVISION
51 
52 # for tests - to be removed
53 ROWS_MAX_BYTES = get_int_value(d=os.environ, key="ROWS_MAX_BYTES", default=DEFAULT_ROWS_MAX_BYTES)
54 ROWS_MAX_NUMBER = get_int_value(d=os.environ, key="ROWS_MAX_NUMBER", default=DEFAULT_ROWS_MAX_NUMBER)
55 ROWS_MIN_NUMBER = get_int_value(d=os.environ, key="ROWS_MIN_NUMBER", default=DEFAULT_ROWS_MIN_NUMBER)
56
```

Path: `src/datasets_preview_backend/models/row.py`
Content:
```
1 import itertools
2 import logging
3 from typing import Any, Dict, List, Optional
4 
5 from datasets import Dataset, DownloadMode, IterableDataset, load_dataset
6 
7 from datasets_preview_backend.constants import DEFAULT_ROWS_MAX_NUMBER
8 from datasets_preview_backend.utils import retry
9 
10 logger = logging.getLogger(__name__)
11 
12 
13 Row = Dict[str, Any]
14 
15 
16 @retry(logger=logger)
17 def get_rows(
18     dataset_name: str,
19     config_name: str,
20     split_name: str,
21     hf_token: Optional[str] = None,
22     streaming: bool = True,
23     rows_max_number: Optional[int] = None,
24 ) -> List[Row]:
25     if rows_max_number is None:
26         rows_max_number = DEFAULT_ROWS_MAX_NUMBER
27     dataset = load_dataset(
28         dataset_name,
29         name=config_name,
30         split=split_name,
31         streaming=True,
32         download_mode=DownloadMode.FORCE_REDOWNLOAD,
33         use_auth_token=hf_token,
34     )
35     if streaming:
36         if not isinstance(dataset, IterableDataset):
37             raise TypeError("load_dataset should return an IterableDataset")
38     elif not isinstance(dataset, Dataset):
39         raise TypeError("load_dataset should return a Dataset")
40     rows_plus_one = list(itertools.islice(dataset, rows_max_number + 1))
41     # ^^ to be able to detect if a split has exactly ROWS_MAX_NUMBER rows
42     if len(rows_plus_one) <= rows_max_number:
43         logger.debug(f"all the rows in the split have been fetched ({len(rows_plus_one)})")
44     else:
45         logger.debug(f"the rows in the split have been truncated ({rows_max_number} rows)")
46     return rows_plus_one[:rows_max_number]
47
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/datasets_preview_backend/config.py b/src/datasets_preview_backend/config.py
--- a/src/datasets_preview_backend/config.py
+++ b/src/datasets_preview_backend/config.py
@@ -12,6 +12,7 @@
     DEFAULT_LOG_LEVEL,
     DEFAULT_MAX_AGE_LONG_SECONDS,
     DEFAULT_MAX_AGE_SHORT_SECONDS,
+    DEFAULT_MAX_SIZE_FALLBACK,
     DEFAULT_MONGO_CACHE_DATABASE,
     DEFAULT_MONGO_QUEUE_DATABASE,
     DEFAULT_MONGO_URL,
@@ -50,6 +51,7 @@
 os.environ["HF_SCRIPTS_VERSION"] = DATASETS_REVISION
 
 # for tests - to be removed
+MAX_SIZE_FALLBACK = get_int_value(os.environ, "MAX_SIZE_FALLBACK", DEFAULT_MAX_SIZE_FALLBACK)
 ROWS_MAX_BYTES = get_int_value(d=os.environ, key="ROWS_MAX_BYTES", default=DEFAULT_ROWS_MAX_BYTES)
 ROWS_MAX_NUMBER = get_int_value(d=os.environ, key="ROWS_MAX_NUMBER", default=DEFAULT_ROWS_MAX_NUMBER)
 ROWS_MIN_NUMBER = get_int_value(d=os.environ, key="ROWS_MIN_NUMBER", default=DEFAULT_ROWS_MIN_NUMBER)
diff --git a/src/datasets_preview_backend/models/row.py b/src/datasets_preview_backend/models/row.py
--- a/src/datasets_preview_backend/models/row.py
+++ b/src/datasets_preview_backend/models/row.py
@@ -28,7 +28,7 @@
         dataset_name,
         name=config_name,
         split=split_name,
-        streaming=True,
+        streaming=streaming,
         download_mode=DownloadMode.FORCE_REDOWNLOAD,
         use_auth_token=hf_token,
     )

{"golden_diff": "diff --git a/src/datasets_preview_backend/config.py b/src/datasets_preview_backend/config.py\n--- a/src/datasets_preview_backend/config.py\n+++ b/src/datasets_preview_backend/config.py\n@@ -12,6 +12,7 @@\n     DEFAULT_LOG_LEVEL,\n     DEFAULT_MAX_AGE_LONG_SECONDS,\n     DEFAULT_MAX_AGE_SHORT_SECONDS,\n+    DEFAULT_MAX_SIZE_FALLBACK,\n     DEFAULT_MONGO_CACHE_DATABASE,\n     DEFAULT_MONGO_QUEUE_DATABASE,\n     DEFAULT_MONGO_URL,\n@@ -50,6 +51,7 @@\n os.environ[\"HF_SCRIPTS_VERSION\"] = DATASETS_REVISION\n \n # for tests - to be removed\n+MAX_SIZE_FALLBACK = get_int_value(os.environ, \"MAX_SIZE_FALLBACK\", DEFAULT_MAX_SIZE_FALLBACK)\n ROWS_MAX_BYTES = get_int_value(d=os.environ, key=\"ROWS_MAX_BYTES\", default=DEFAULT_ROWS_MAX_BYTES)\n ROWS_MAX_NUMBER = get_int_value(d=os.environ, key=\"ROWS_MAX_NUMBER\", default=DEFAULT_ROWS_MAX_NUMBER)\n ROWS_MIN_NUMBER = get_int_value(d=os.environ, key=\"ROWS_MIN_NUMBER\", default=DEFAULT_ROWS_MIN_NUMBER)\ndiff --git a/src/datasets_preview_backend/models/row.py b/src/datasets_preview_backend/models/row.py\n--- a/src/datasets_preview_backend/models/row.py\n+++ b/src/datasets_preview_backend/models/row.py\n@@ -28,7 +28,7 @@\n         dataset_name,\n         name=config_name,\n         split=split_name,\n-        streaming=True,\n+        streaming=streaming,\n         download_mode=DownloadMode.FORCE_REDOWNLOAD,\n         use_auth_token=hf_token,\n     )\n", "issue": "regression: fallback if streaming fails is disabled\nCauses https://github.com/huggingface/datasets/issues/3185 for example: the fallback should have loaded the dataset in normal mode.\n", "before_files": [{"content": "import os\n\nfrom dotenv import load_dotenv\n\nfrom datasets_preview_backend.constants import (\n    DEFAULT_APP_HOSTNAME,\n    DEFAULT_APP_PORT,\n    DEFAULT_ASSETS_DIRECTORY,\n    DEFAULT_DATASETS_ENABLE_PRIVATE,\n    DEFAULT_DATASETS_REVISION,\n    DEFAULT_HF_TOKEN,\n    DEFAULT_LOG_LEVEL,\n    DEFAULT_MAX_AGE_LONG_SECONDS,\n    DEFAULT_MAX_AGE_SHORT_SECONDS,\n    DEFAULT_MONGO_CACHE_DATABASE,\n    DEFAULT_MONGO_QUEUE_DATABASE,\n    DEFAULT_MONGO_URL,\n    DEFAULT_ROWS_MAX_BYTES,\n    DEFAULT_ROWS_MAX_NUMBER,\n    DEFAULT_ROWS_MIN_NUMBER,\n    DEFAULT_WEB_CONCURRENCY,\n)\nfrom datasets_preview_backend.utils import (\n    get_bool_value,\n    get_int_value,\n    get_str_or_none_value,\n    get_str_value,\n)\n\n# Load environment variables defined in .env, if any\nload_dotenv()\n\nAPP_HOSTNAME = get_str_value(d=os.environ, key=\"APP_HOSTNAME\", default=DEFAULT_APP_HOSTNAME)\nAPP_PORT = get_int_value(d=os.environ, key=\"APP_PORT\", default=DEFAULT_APP_PORT)\nASSETS_DIRECTORY = get_str_or_none_value(d=os.environ, key=\"ASSETS_DIRECTORY\", default=DEFAULT_ASSETS_DIRECTORY)\nDATASETS_ENABLE_PRIVATE = get_bool_value(\n    d=os.environ, key=\"DATASETS_ENABLE_PRIVATE\", default=DEFAULT_DATASETS_ENABLE_PRIVATE\n)\nDATASETS_REVISION = get_str_value(d=os.environ, key=\"DATASETS_REVISION\", default=DEFAULT_DATASETS_REVISION)\nHF_TOKEN = get_str_or_none_value(d=os.environ, key=\"HF_TOKEN\", default=DEFAULT_HF_TOKEN)\nLOG_LEVEL = get_str_value(d=os.environ, key=\"LOG_LEVEL\", default=DEFAULT_LOG_LEVEL)\nMAX_AGE_LONG_SECONDS = get_int_value(d=os.environ, key=\"MAX_AGE_LONG_SECONDS\", default=DEFAULT_MAX_AGE_LONG_SECONDS)\nMAX_AGE_SHORT_SECONDS = get_int_value(d=os.environ, key=\"MAX_AGE_SHORT_SECONDS\", default=DEFAULT_MAX_AGE_SHORT_SECONDS)\nMONGO_CACHE_DATABASE = get_str_value(d=os.environ, key=\"MONGO_CACHE_DATABASE\", default=DEFAULT_MONGO_CACHE_DATABASE)\nMONGO_QUEUE_DATABASE = get_str_value(d=os.environ, key=\"MONGO_QUEUE_DATABASE\", default=DEFAULT_MONGO_QUEUE_DATABASE)\nMONGO_URL = get_str_value(d=os.environ, key=\"MONGO_URL\", default=DEFAULT_MONGO_URL)\nWEB_CONCURRENCY = get_int_value(d=os.environ, key=\"WEB_CONCURRENCY\", default=DEFAULT_WEB_CONCURRENCY)\n\n# Ensure datasets library uses the expected revision for canonical datasets\nos.environ[\"HF_SCRIPTS_VERSION\"] = DATASETS_REVISION\n\n# for tests - to be removed\nROWS_MAX_BYTES = get_int_value(d=os.environ, key=\"ROWS_MAX_BYTES\", default=DEFAULT_ROWS_MAX_BYTES)\nROWS_MAX_NUMBER = get_int_value(d=os.environ, key=\"ROWS_MAX_NUMBER\", default=DEFAULT_ROWS_MAX_NUMBER)\nROWS_MIN_NUMBER = get_int_value(d=os.environ, key=\"ROWS_MIN_NUMBER\", default=DEFAULT_ROWS_MIN_NUMBER)\n", "path": "src/datasets_preview_backend/config.py"}, {"content": "import itertools\nimport logging\nfrom typing import Any, Dict, List, Optional\n\nfrom datasets import Dataset, DownloadMode, IterableDataset, load_dataset\n\nfrom datasets_preview_backend.constants import DEFAULT_ROWS_MAX_NUMBER\nfrom datasets_preview_backend.utils import retry\n\nlogger = logging.getLogger(__name__)\n\n\nRow = Dict[str, Any]\n\n\n@retry(logger=logger)\ndef get_rows(\n    dataset_name: str,\n    config_name: str,\n    split_name: str,\n    hf_token: Optional[str] = None,\n    streaming: bool = True,\n    rows_max_number: Optional[int] = None,\n) -> List[Row]:\n    if rows_max_number is None:\n        rows_max_number = DEFAULT_ROWS_MAX_NUMBER\n    dataset = load_dataset(\n        dataset_name,\n        name=config_name,\n        split=split_name,\n        streaming=True,\n        download_mode=DownloadMode.FORCE_REDOWNLOAD,\n        use_auth_token=hf_token,\n    )\n    if streaming:\n        if not isinstance(dataset, IterableDataset):\n            raise TypeError(\"load_dataset should return an IterableDataset\")\n    elif not isinstance(dataset, Dataset):\n        raise TypeError(\"load_dataset should return a Dataset\")\n    rows_plus_one = list(itertools.islice(dataset, rows_max_number + 1))\n    # ^^ to be able to detect if a split has exactly ROWS_MAX_NUMBER rows\n    if len(rows_plus_one) <= rows_max_number:\n        logger.debug(f\"all the rows in the split have been fetched ({len(rows_plus_one)})\")\n    else:\n        logger.debug(f\"the rows in the split have been truncated ({rows_max_number} rows)\")\n    return rows_plus_one[:rows_max_number]\n", "path": "src/datasets_preview_backend/models/row.py"}], "after_files": [{"content": "import os\n\nfrom dotenv import load_dotenv\n\nfrom datasets_preview_backend.constants import (\n    DEFAULT_APP_HOSTNAME,\n    DEFAULT_APP_PORT,\n    DEFAULT_ASSETS_DIRECTORY,\n    DEFAULT_DATASETS_ENABLE_PRIVATE,\n    DEFAULT_DATASETS_REVISION,\n    DEFAULT_HF_TOKEN,\n    DEFAULT_LOG_LEVEL,\n    DEFAULT_MAX_AGE_LONG_SECONDS,\n    DEFAULT_MAX_AGE_SHORT_SECONDS,\n    DEFAULT_MAX_SIZE_FALLBACK,\n    DEFAULT_MONGO_CACHE_DATABASE,\n    DEFAULT_MONGO_QUEUE_DATABASE,\n    DEFAULT_MONGO_URL,\n    DEFAULT_ROWS_MAX_BYTES,\n    DEFAULT_ROWS_MAX_NUMBER,\n    DEFAULT_ROWS_MIN_NUMBER,\n    DEFAULT_WEB_CONCURRENCY,\n)\nfrom datasets_preview_backend.utils import (\n    get_bool_value,\n    get_int_value,\n    get_str_or_none_value,\n    get_str_value,\n)\n\n# Load environment variables defined in .env, if any\nload_dotenv()\n\nAPP_HOSTNAME = get_str_value(d=os.environ, key=\"APP_HOSTNAME\", default=DEFAULT_APP_HOSTNAME)\nAPP_PORT = get_int_value(d=os.environ, key=\"APP_PORT\", default=DEFAULT_APP_PORT)\nASSETS_DIRECTORY = get_str_or_none_value(d=os.environ, key=\"ASSETS_DIRECTORY\", default=DEFAULT_ASSETS_DIRECTORY)\nDATASETS_ENABLE_PRIVATE = get_bool_value(\n    d=os.environ, key=\"DATASETS_ENABLE_PRIVATE\", default=DEFAULT_DATASETS_ENABLE_PRIVATE\n)\nDATASETS_REVISION = get_str_value(d=os.environ, key=\"DATASETS_REVISION\", default=DEFAULT_DATASETS_REVISION)\nHF_TOKEN = get_str_or_none_value(d=os.environ, key=\"HF_TOKEN\", default=DEFAULT_HF_TOKEN)\nLOG_LEVEL = get_str_value(d=os.environ, key=\"LOG_LEVEL\", default=DEFAULT_LOG_LEVEL)\nMAX_AGE_LONG_SECONDS = get_int_value(d=os.environ, key=\"MAX_AGE_LONG_SECONDS\", default=DEFAULT_MAX_AGE_LONG_SECONDS)\nMAX_AGE_SHORT_SECONDS = get_int_value(d=os.environ, key=\"MAX_AGE_SHORT_SECONDS\", default=DEFAULT_MAX_AGE_SHORT_SECONDS)\nMONGO_CACHE_DATABASE = get_str_value(d=os.environ, key=\"MONGO_CACHE_DATABASE\", default=DEFAULT_MONGO_CACHE_DATABASE)\nMONGO_QUEUE_DATABASE = get_str_value(d=os.environ, key=\"MONGO_QUEUE_DATABASE\", default=DEFAULT_MONGO_QUEUE_DATABASE)\nMONGO_URL = get_str_value(d=os.environ, key=\"MONGO_URL\", default=DEFAULT_MONGO_URL)\nWEB_CONCURRENCY = get_int_value(d=os.environ, key=\"WEB_CONCURRENCY\", default=DEFAULT_WEB_CONCURRENCY)\n\n# Ensure datasets library uses the expected revision for canonical datasets\nos.environ[\"HF_SCRIPTS_VERSION\"] = DATASETS_REVISION\n\n# for tests - to be removed\nMAX_SIZE_FALLBACK = get_int_value(os.environ, \"MAX_SIZE_FALLBACK\", DEFAULT_MAX_SIZE_FALLBACK)\nROWS_MAX_BYTES = get_int_value(d=os.environ, key=\"ROWS_MAX_BYTES\", default=DEFAULT_ROWS_MAX_BYTES)\nROWS_MAX_NUMBER = get_int_value(d=os.environ, key=\"ROWS_MAX_NUMBER\", default=DEFAULT_ROWS_MAX_NUMBER)\nROWS_MIN_NUMBER = get_int_value(d=os.environ, key=\"ROWS_MIN_NUMBER\", default=DEFAULT_ROWS_MIN_NUMBER)\n", "path": "src/datasets_preview_backend/config.py"}, {"content": "import itertools\nimport logging\nfrom typing import Any, Dict, List, Optional\n\nfrom datasets import Dataset, DownloadMode, IterableDataset, load_dataset\n\nfrom datasets_preview_backend.constants import DEFAULT_ROWS_MAX_NUMBER\nfrom datasets_preview_backend.utils import retry\n\nlogger = logging.getLogger(__name__)\n\n\nRow = Dict[str, Any]\n\n\n@retry(logger=logger)\ndef get_rows(\n    dataset_name: str,\n    config_name: str,\n    split_name: str,\n    hf_token: Optional[str] = None,\n    streaming: bool = True,\n    rows_max_number: Optional[int] = None,\n) -> List[Row]:\n    if rows_max_number is None:\n        rows_max_number = DEFAULT_ROWS_MAX_NUMBER\n    dataset = load_dataset(\n        dataset_name,\n        name=config_name,\n        split=split_name,\n        streaming=streaming,\n        download_mode=DownloadMode.FORCE_REDOWNLOAD,\n        use_auth_token=hf_token,\n    )\n    if streaming:\n        if not isinstance(dataset, IterableDataset):\n            raise TypeError(\"load_dataset should return an IterableDataset\")\n    elif not isinstance(dataset, Dataset):\n        raise TypeError(\"load_dataset should return a Dataset\")\n    rows_plus_one = list(itertools.islice(dataset, rows_max_number + 1))\n    # ^^ to be able to detect if a split has exactly ROWS_MAX_NUMBER rows\n    if len(rows_plus_one) <= rows_max_number:\n        logger.debug(f\"all the rows in the split have been fetched ({len(rows_plus_one)})\")\n    else:\n        logger.debug(f\"the rows in the split have been truncated ({rows_max_number} rows)\")\n    return rows_plus_one[:rows_max_number]\n", "path": "src/datasets_preview_backend/models/row.py"}]}