internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: learningequality/kolibri

Issue:
Environment variables and configuration flags for Kolibri options are persisted to the `options.ini` file by `generate_empty_options_file`
## Observed behavior
When using either environment variables or configuration flags like `--port` or `--debug` on the first run of a Kolibri device, these will be written to the empty `options.ini` file generated by `generate_empty_options_file` - this means that settings chosen on the first run by ephemeral configuration like environment variables and runtime flags will be persisted for subsequent runs of the server.

## Expected behavior
Ephemeral configuration should not be persisted to disk.

## User-facing consequences
The main place this could be problematic is if someone is using a base Kolibri to generate a `KOLIBRI_HOME` image and they do not intend their configuration flags to be persisted.

Additionally, Kolibri developers might be confused why flags are being persisted when they shouldn't.

## Steps to reproduce
Run kolibri with a new `KOLIBRI_HOME` directory. Run with the `--debug` flag.

See that `options.ini` contains an uncommented line `DEBUG = True`

## Context
Tell us about your environment, including:
 * Kolibri version: 0.15.5
 * Operating system: Ubuntu


Discussion:
I want to work on this.
Hi @thesujai. I have assigned this issue to you :smile:

Resolving patch:
diff --git a/kolibri/utils/options.py b/kolibri/utils/options.py
--- a/kolibri/utils/options.py
+++ b/kolibri/utils/options.py
@@ -992,6 +992,12 @@ def generate_empty_options_file(ini_filename="options.ini"):
 
     conf = read_options_file(ini_filename=ini_filename)
 
+    for section, opts in option_spec.items():
+        for optname, attrs in opts.items():
+            for envvar in attrs.get("envvars", []):
+                if envvar in os.environ:
+                    conf[section].pop(optname, None)
+
     comments = None
 
     for section, opts in option_spec.items():


Test patch:
Repository: learningequality/kolibri

Issue:
Only call render on the response if it has a render method
AttributeError: 'HttpResponseNotAllowed' object has no attribute 'render'

Sentry Issue: [KOLIBRI-BACKEND-2BQ](https://learningequality.sentry.io/issues/3692557332/?referrer=github_integration)

```
AttributeError: 'HttpResponseNotAllowed' object has no attribute 'render'
(3 additional frame(s) were not displayed)
...
  File "django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "django/utils/decorators.py", line 67, in _wrapper
    return bound_func(*args, **kwargs)
  File "django/views/decorators/http.py", line 99, in inner
    response = func(request, *args, **kwargs)
  File "kolibri/core/decorators.py", line 374, in inner_func
    render_and_cache(response, CACHE_KEY_TEMPLATE.format(request.path))
  File "kolibri/core/decorators.py", line 342, in render_and_cache
    response.render()
```


Discussion:
@rtibbles It's just a simple fix according to me. We just have to check whether the _response_ object has the _render_ attribute or not before calling `response.render()` in the `render_and_cache` function. Could you please assign this issue to me?
Thanks :)

Resolving patch:
diff --git a/kolibri/core/decorators.py b/kolibri/core/decorators.py
--- a/kolibri/core/decorators.py
+++ b/kolibri/core/decorators.py
@@ -339,12 +339,16 @@ def cache_no_user_data(view_func):
     _response = local()
 
     def render_and_cache(response, cache_key):
-        response.render()
-        etag = hashlib.md5(
-            kolibri_version.encode("utf-8") + str(response.content).encode("utf-8")
-        ).hexdigest()
-        cache.set(cache_key, etag, CACHE_TIMEOUT)
-        return etag
+        if hasattr(response, "render") and callable(response.render):
+            response.render()
+        if response.content:
+            etag = hashlib.md5(
+                kolibri_version.encode("utf-8") + str(response.content).encode("utf-8")
+            ).hexdigest()
+            cache.set(cache_key, etag, CACHE_TIMEOUT)
+            return etag
+        else:
+            return None
 
     def calculate_spa_etag(*args, **kwargs):
         # Clear the local thread 'response' property


Test patch:
Repository: learningequality/kolibri

Issue:
Setup Wizard - Broken facility/LOD import
## Observed behavior

Currently both the import of a facility or the import/creation of LOD are not working (getting a `http://127.0.0.1:8080/api/device/deviceprovision/ 400 (Bad Request)` error in the console). 
This issue was initially observed by @radinamatic while regression testing https://github.com/learningequality/kolibri/pull/11756 and the [latest Beta 11](https://github.com/learningequality/kolibri/releases/tag/v0.16.0-beta11).

https://github.com/learningequality/kolibri/assets/79847249/7c93f1b7-f11a-4ac4-92db-45a5bb1e07d5

## Expected behavior

Fully functional full facility import and import/creation of a LOD.

## Steps to reproduce the issue

1. Install the [latest Beta 11 build asset](https://github.com/learningequality/kolibri/releases/tag/v0.16.0-beta11).
2. Setup a server device with created users.
3. On a different device start the Setup Wizard and go through the workflows for importing a full facility or importing/creating a learn-only device.

## Logs

[UbuntuDevice.zip](https://github.com/learningequality/kolibri/files/14010143/UbuntuDevice.zip)
[WindowsServer.zip](https://github.com/learningequality/kolibri/files/14010144/WindowsServer.zip)
[Error details.txt](https://github.com/learningequality/kolibri/files/14010159/Error.details.txt)

## Usage Details
[Beta 11](https://github.com/learningequality/kolibri/releases/tag/v0.16.0-beta11)
Ubuntu 22  - Chrome


Discussion:
@radinamatic 
Can i work on this? 
@nick2432 As this is a high priority, critical issue with regards to our Kolibri 0.16 release, it isn't suitable for contributors. Thank you for interest though! 

Resolving patch:
diff --git a/kolibri/core/device/serializers.py b/kolibri/core/device/serializers.py
--- a/kolibri/core/device/serializers.py
+++ b/kolibri/core/device/serializers.py
@@ -52,7 +52,7 @@ def validate_language_id(self, language_id):
 class DeviceProvisionSerializer(DeviceSerializerMixin, serializers.Serializer):
     facility = FacilitySerializer(required=False, allow_null=True)
     facility_id = serializers.CharField(max_length=50, required=False, allow_null=True)
-    preset = serializers.ChoiceField(choices=choices)
+    preset = serializers.ChoiceField(choices=choices, required=False, allow_null=True)
     superuser = NoFacilityFacilityUserSerializer(required=False)
     language_id = serializers.CharField(max_length=15)
     device_name = serializers.CharField(max_length=50, allow_null=True)


Test patch:
Repository: learningequality/kolibri

Issue:
'On my own' device - Merging a user is not working
## Observed behavior
Observed while integration testing the [v0.16.1-beta1 ](https://github.com/learningequality/kolibri/releases/tag/v0.16.1-beta1) release.
When I try to merge a user created through 'On my own' I am getting an "Invalid URL" error in the console. Note that creating a new account through the same flow is working correctly. This issue is caused by the changes made in https://github.com/learningequality/kolibri/pull/12028 and is not extant in [v0.16.1-beta0](https://github.com/learningequality/kolibri/releases/tag/v0.16.1-beta0).

https://github.com/learningequality/kolibri/assets/79847249/30daa3ca-918c-4c15-901b-c74c08b96466

## Expected behavior

Fully functional 'Merge accounts' user flow. 

## Steps to reproduce the issue

1. Install [v0.16.1-beta1 ](https://github.com/learningequality/kolibri/releases/tag/v0.16.1-beta1).
2. Setup a full device as a server and another device by going through the 'On my own' setup flow.
3. Attempt to merge the user from the 'On my own' device' to the server facility.

## Logs

[logs.zip](https://github.com/learningequality/kolibri/files/14850735/logs.zip)

## Usage Details
[v0.16.1-beta1 ](https://github.com/learningequality/kolibri/releases/tag/v0.16.1-beta1)
Windows 11, Ubuntu 22  - Chrome


Discussion:
@radinamatic @rtibbles 
Thanks @pcenov - this probably indicates that the frontend is doing something wrong, can update!

Resolving patch:
diff --git a/kolibri/plugins/user_profile/viewsets.py b/kolibri/plugins/user_profile/viewsets.py
--- a/kolibri/plugins/user_profile/viewsets.py
+++ b/kolibri/plugins/user_profile/viewsets.py
@@ -53,7 +53,7 @@ def get(self, request):
 
 class RemoteFacilityUserAuthenticatedViewset(APIView):
     def post(self, request, *args, **kwargs):
-        baseurl = request.query_params.get("baseurl", "")
+        baseurl = request.data.get("baseurl", "")
         try:
             validator(baseurl)
         except DjangoValidationError as e:


Test patch:
Repository: learningequality/kolibri

Issue:
Change learning facility - Getting a 400 error "Invalid_username" while changing the facility
## Observed behavior

When the `Require password for learners` option at `Facility > Settings` is left unchecked and I attempt to change my facility from an 'On my own' device, then I am getting into an infinite loop:

https://github.com/learningequality/kolibri/assets/79847249/d538e64b-f730-4339-81a3-5b12dc1daa9c

I checked the 0.16.1 version of Kolibri and it's extant there as well.

## Expected behavior

It should be possible to change the learning facility.

## Steps to reproduce the issue

1. Install Kolibri 0.16.2b2 on two devices one of which is of type 'Formal facility' and the other one is an 'On my own'
2. On the 'On my own' device go to the Profile page and click the 'Change' button
3. Keep clicking the 'Continue' button and observe that clicking 'Continue' at 'Confirm account username' brings the user back to 'Change learning facility'.

##Logs

[on-my-own-logs.zip](https://github.com/learningequality/kolibri/files/15405325/on-my-own-logs.zip)

[server-logs.zip](https://github.com/learningequality/kolibri/files/15405338/server-logs.zip)

## Usage Details
Kolibri 0.16.2b2
Windows 11, Ubuntu 22  - Chrome, Firefox


Discussion:
@radinamatic 
@marcellamaki This is not a regression but looks serious... 🤔 
yes, we will fix this for the patch. Thank you @pcenov !


Resolving patch:
diff --git a/kolibri/plugins/user_profile/tasks.py b/kolibri/plugins/user_profile/tasks.py
--- a/kolibri/plugins/user_profile/tasks.py
+++ b/kolibri/plugins/user_profile/tasks.py
@@ -45,7 +45,10 @@ def validate(self, data):
             details = e.detail if isinstance(e.detail, list) else [e.detail]
             for detail in details:
                 # If any of the errors are authentication related, then we need to create the user
-                if detail.code == error_constants.AUTHENTICATION_FAILED:
+                if (
+                    detail.code == error_constants.AUTHENTICATION_FAILED
+                    or detail.code == error_constants.INVALID_USERNAME
+                ):
                     self.create_remote_user(data)
                     job_data = super(MergeUserValidator, self).validate(data)
                     break


Test patch:
Repository: microsoft/nni

Issue:
BUG in spos evolution part
I trained the spos from scratch with supernet.py, but failed to load the checkpoints. It turned out there was a mismatch between load and save part. 

In  the save part  https://github.com/microsoft/nni/blob/69dfbf5e976cf75e89949af4764928dde631a3f6/src/sdk/pynni/nni/nas/pytorch/callbacks.py#L136,  no dict was used. But in the load part,  https://github.com/microsoft/nni/blob/69dfbf5e976cf75e89949af4764928dde631a3f6/examples/nas/spos/network.py#L151,  key 'state_dict' was used. It failed to load the checkpoint. After removing 'state_dict', checkpoint could be loaded and problem was solved.




Discussion:
Thanks @xingwangsfu !

@ultmaster  may you help to confirm whether this is a bug and is @xingwangsfu 's fix okey for submit a PR directly? 

Resolving patch:
diff --git a/examples/nas/spos/network.py b/examples/nas/spos/network.py
--- a/examples/nas/spos/network.py
+++ b/examples/nas/spos/network.py
@@ -147,8 +147,10 @@ def _initialize_weights(self):
 
 def load_and_parse_state_dict(filepath="./data/checkpoint-150000.pth.tar"):
     checkpoint = torch.load(filepath, map_location=torch.device("cpu"))
+    if "state_dict" in checkpoint:
+        checkpoint = checkpoint["state_dict"]
     result = dict()
-    for k, v in checkpoint["state_dict"].items():
+    for k, v in checkpoint.items():
         if k.startswith("module."):
             k = k[len("module."):]
         result[k] = v


Test patch:
Repository: microsoft/nni

Issue:
Is StackedLSTMCell correct implementation?
For enas, StackedLSTMCell is implemented as below
 https://github.com/microsoft/nni/blob/bf8be1e705cdc0c153d6f38d1a83bd3fe55d7a1e/src/sdk/pynni/nni/nas/pytorch/enas/mutator.py#L23-L28

nn.LSTMCell outputs (hidden state, cell state) but the order of output is changed in the implementation.
As a result, the cell state is used for output of LSTM.

Is this an intention or wrong implementation?


Discussion:
Hi @jyh2986. Thanks for asking.

If you are right, the implementation is definitely buggy. You can raise a PR. Meanwhile, I'll check the PyTorch documentation for verification. Thanks.

Resolving patch:
diff --git a/src/sdk/pynni/nni/nas/pytorch/enas/mutator.py b/src/sdk/pynni/nni/nas/pytorch/enas/mutator.py
--- a/src/sdk/pynni/nni/nas/pytorch/enas/mutator.py
+++ b/src/sdk/pynni/nni/nas/pytorch/enas/mutator.py
@@ -17,16 +17,16 @@ def __init__(self, layers, size, bias):
                                            for _ in range(self.lstm_num_layers)])
 
     def forward(self, inputs, hidden):
-        prev_c, prev_h = hidden
-        next_c, next_h = [], []
+        prev_h, prev_c = hidden
+        next_h, next_c = [], []
         for i, m in enumerate(self.lstm_modules):
-            curr_c, curr_h = m(inputs, (prev_c[i], prev_h[i]))
+            curr_h, curr_c = m(inputs, (prev_h[i], prev_c[i]))
             next_c.append(curr_c)
             next_h.append(curr_h)
             # current implementation only supports batch size equals 1,
             # but the algorithm does not necessarily have this limitation
             inputs = curr_h[-1].view(1, -1)
-        return next_c, next_h
+        return next_h, next_c
 
 
 class EnasMutator(Mutator):
@@ -136,7 +136,7 @@ def _initialize(self):
         self.sample_skip_penalty = 0
 
     def _lstm_next_step(self):
-        self._c, self._h = self.lstm(self._inputs, (self._c, self._h))
+        self._h, self._c = self.lstm(self._inputs, (self._h, self._c))
 
     def _mark_anchor(self, key):
         self._anchors_hid[key] = self._h[-1]


Test patch:
Repository: microsoft/nni

Issue:
`nni.trace` + `pickle` don't play well together under non-linux envs
Test case:

```python
def test_multiprocessing_dataloader():
    # check whether multi-processing works
    # it's possible to have pickle errors
    dataset = MNIST(root='data/mnist', train=False, download=True,
                               transform=nni.trace(transforms.Compose)(
                                   [transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))]
                               ))
    import nni.retiarii.evaluator.pytorch.lightning as pl
    dataloader = pl.DataLoader(dataset, batch_size=10, num_workers=2)
    x, y = next(iter(dataloader))
    assert x.size() == torch.Size([10, 1, 28, 28])
    assert y.size() == torch.Size([10])
```

Error:

```
_pickle.PicklingError: Can't pickle <class 'torchvision.datasets.mnist.MNIST'>: it's not the same object as torchvision.datasets.mnist.MNIST
```

Actually, this won't work either:

```python
pickle.dumps(nni.trace(MNIST))
pickle.dumps(nni.trace(math.sqrt))
```

Related SO: https://stackoverflow.com/questions/1412787/picklingerror-cant-pickle-class-decimal-decimal-its-not-the-same-object

Fixes are non-trivial. Mark as known issue. Won't fix in v2.6.


Discussion:

Resolving patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -115,9 +115,6 @@
 # Set bibliography style
 bibtex_default_style = 'plain'
 
-# Bibliography files
-bibtex_bibfiles = ['refs.bib']
-
 # Sphinx gallery examples
 sphinx_gallery_conf = {
     'examples_dirs': '../../examples/tutorials',   # path to your example scripts


Test patch:
Repository: nonebot/nonebot2

Issue:
在 nonebot-test 前端调试时无法让 Bot 说出 <test>
nonebot.load_builtin_plugins() 后，在 nonebot-test 前端向 Bot 发送 /say <test> 

Bot 未发送任何消息，且 nonebot2 控制台返回：

```
[ERROR] nonebot_test | Tag "<test>" does not corespond to any known ansi directive, make sure you did not misspelled it (or prepend '\' to escape it)
```


Discussion:
由于 `loguru` 使用 `<tag>` 标记颜色，消息内容未进行转义导致报错

Resolving patch:
diff --git a/nonebot/__init__.py b/nonebot/__init__.py
--- a/nonebot/__init__.py
+++ b/nonebot/__init__.py
@@ -109,6 +109,7 @@ def get_bots() -> Union[NoReturn, Dict[str, Bot]]:
 
 
 from nonebot.sched import scheduler
+from nonebot.utils import escape_tag
 from nonebot.config import Env, Config
 from nonebot.log import logger, default_filter
 from nonebot.adapters.cqhttp import Bot as CQBot
@@ -155,8 +156,8 @@ def init(*, _env_file: Optional[str] = None, **kwargs):
                         _env_file=_env_file or f".env.{env.environment}")
 
         default_filter.level = "DEBUG" if config.debug else "INFO"
-        logger.opt(
-            colors=True).debug(f"Loaded <y><b>Config</b></y>: {config.dict()}")
+        logger.opt(colors=True).debug(
+            f"Loaded <y><b>Config</b></y>: {escape_tag(str(config.dict()))}")
 
         DriverClass: Type[Driver] = getattr(
             importlib.import_module(config.driver), "Driver")
diff --git a/nonebot/message.py b/nonebot/message.py
--- a/nonebot/message.py
+++ b/nonebot/message.py
@@ -6,6 +6,7 @@
 
 from nonebot.log import logger
 from nonebot.rule import TrieRule
+from nonebot.utils import escape_tag
 from nonebot.matcher import matchers
 from nonebot.typing import Set, Type, Union, NoReturn
 from nonebot.typing import Bot, Event, Matcher, PreProcessor
@@ -64,7 +65,9 @@ async def handle_event(bot: Bot, event: Event):
             log_msg += f"@[群:{event.group_id}]:"
 
         log_msg += ' "' + "".join(
-            map(lambda x: str(x) if x.type == "text" else f"<le>{x!s}</le>",
+            map(
+                lambda x: escape_tag(str(x))
+                if x.type == "text" else f"<le>{escape_tag(str(x))}</le>",
                 event.message)) + '"'  # type: ignore
     elif event.type == "notice":
         log_msg += f"Notice {event.raw_event}"
diff --git a/nonebot/utils.py b/nonebot/utils.py
--- a/nonebot/utils.py
+++ b/nonebot/utils.py
@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
+import re
 import json
 import asyncio
 import dataclasses
@@ -9,6 +10,10 @@
 from nonebot.typing import Any, Callable, Awaitable, overrides
 
 
+def escape_tag(s: str) -> str:
+    return re.sub(r"</?((?:[fb]g\s)?[^<>\s]*)>", r"\\\g<0>", s)
+
+
 def run_sync(func: Callable[..., Any]) -> Callable[..., Awaitable[Any]]:
     """
     :说明:


Test patch:
Repository: nonebot/nonebot2

Issue:
修复阻止事件传递信号无效的问题
抛出的异常应为 StopPropagation 的一个实例


Discussion:

Resolving patch:
diff --git a/nonebot/message.py b/nonebot/message.py
--- a/nonebot/message.py
+++ b/nonebot/message.py
@@ -244,7 +244,7 @@ async def handle_event(bot: Bot, event: Event):
         results = await asyncio.gather(*pending_tasks, return_exceptions=True)
 
         for result in results:
-            if result is StopPropagation:
+            if isinstance(result, StopPropagation):
                 if not break_flag:
                     break_flag = True
                     logger.debug("Stop event propagation")


Test patch:
Repository: nonebot/nonebot2

Issue:
Bug: expired matcher 在删除前依然会运行
**描述问题：**

超出有效期的事件响应器在删除前仍然会运行一次

**期望的结果**

超出有效期的事件响应器不被运行

**环境信息：**

 - OS: Any
 - Python Version: Any
 - Nonebot Version: 2.0.0a6
Bug: expired matcher 在删除前依然会运行
**描述问题：**

超出有效期的事件响应器在删除前仍然会运行一次

**期望的结果**

超出有效期的事件响应器不被运行

**环境信息：**

 - OS: Any
 - Python Version: Any
 - Nonebot Version: 2.0.0a6


Discussion:

Resolving patch:
diff --git a/nonebot/message.py b/nonebot/message.py
--- a/nonebot/message.py
+++ b/nonebot/message.py
@@ -92,8 +92,9 @@ async def _check_matcher(priority: int, bot: Bot, event: Event,
     async def _check(Matcher: Type[Matcher], bot: Bot, event: Event,
                      state: dict) -> Optional[Type[Matcher]]:
         try:
-            if await Matcher.check_perm(
-                    bot, event) and await Matcher.check_rule(bot, event, state):
+            if (Matcher.expire_time and datetime.now() <= Matcher.expire_time
+               ) and await Matcher.check_perm(
+                   bot, event) and await Matcher.check_rule(bot, event, state):
                 return Matcher
         except Exception as e:
             logger.opt(colors=True, exception=e).error(


Test patch:
Repository: nonebot/nonebot2

Issue:
Bug: expired matcher 在删除前依然会运行
**描述问题：**

超出有效期的事件响应器在删除前仍然会运行一次

**期望的结果**

超出有效期的事件响应器不被运行

**环境信息：**

 - OS: Any
 - Python Version: Any
 - Nonebot Version: 2.0.0a6


Discussion:

Resolving patch:
diff --git a/packages/nonebot-plugin-docs/nonebot_plugin_docs/__init__.py b/packages/nonebot-plugin-docs/nonebot_plugin_docs/__init__.py
new file mode 100644
--- /dev/null
+++ b/packages/nonebot-plugin-docs/nonebot_plugin_docs/__init__.py
@@ -0,0 +1,25 @@
+import importlib
+
+import nonebot
+from nonebot.log import logger
+
+
+def init():
+    driver = nonebot.get_driver()
+    try:
+        _module = importlib.import_module(
+            f"nonebot_plugin_docs.drivers.{driver.type}")
+    except ImportError:
+        logger.warning(f"Driver {driver.type} not supported")
+        return
+    register_route = getattr(_module, "register_route")
+    register_route(driver)
+    host = str(driver.config.host)
+    port = driver.config.port
+    if host in ["0.0.0.0", "127.0.0.1"]:
+        host = "localhost"
+    logger.opt(colors=True).info(f"Nonebot docs will be running at: "
+                                 f"<b><u>http://{host}:{port}/docs/</u></b>")
+
+
+init()
diff --git a/packages/nonebot-plugin-docs/nonebot_plugin_docs/drivers/fastapi.py b/packages/nonebot-plugin-docs/nonebot_plugin_docs/drivers/fastapi.py
new file mode 100644
--- /dev/null
+++ b/packages/nonebot-plugin-docs/nonebot_plugin_docs/drivers/fastapi.py
@@ -0,0 +1,14 @@
+from pathlib import Path
+
+from nonebot.drivers.fastapi import Driver
+from fastapi.staticfiles import StaticFiles
+
+
+def register_route(driver: Driver):
+    app = driver.server_app
+
+    static_path = str((Path(__file__).parent / ".." / "dist").resolve())
+
+    app.mount("/docs",
+              StaticFiles(directory=static_path, html=True),
+              name="docs")


Test patch: