kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

[Bug]: Cannot save options.ini when a path contains non-ASCII characters (UnicodeEncodeError)

Open Darshanpawar7 opened this issue 3 weeks ago • 2 comments

🙂 Looking for an issue? Welcome! This issue is open for contribution. If this is the first time you’re requesting an issue, please:

  • Read Contributing guidelines carefully. Pay extra attention to Using generative AI. Pull requests and comments that don’t follow the guidelines won’t be answered.
  • Confirm that you’ve read the guidelines in your comment.

Description

Describe the bug

Kolibri can read options.ini values that contain non-ASCII characters (for example é or ó), but it cannot save the file afterwards. Saving raises:

UnicodeEncodeError: 'ascii' codec can't encode character ...

This affects any save that rewrites options.ini, including Device > Settings and kolibri manage content movedirectory.

The cause is in kolibri/utils/options.py: ConfigObj(ini_path, configspec=get_configspec()) is created without an encoding. configobj then reads the file as UTF-8 but writes it as ASCII. Because Kolibri rewrites the whole file on every save, one non-ASCII value in the file breaks every later save, even for an unrelated setting like HTTP_PORT.

To Reproduce

  1. Start Kolibri with a fresh KOLIBRI_HOME.
  2. Try to save a storage location whose path contains a non-ASCII character, e.g. /media/usb/Vidéos. This is the request Device > Settings sends.
  3. Observe HTTP 500 / UnicodeEncodeError; nothing is saved.

For movedirectory:

  1. Run kolibri configure setup.
  2. Put a file in $KOLIBRI_HOME/content/databases.
  3. Run kolibri manage content movedirectory "/media/usb/Vidéos".
  4. The command copies the content and empties the old folder, then crashes with UnicodeEncodeError. CONTENT_DIR is not updated, so Kolibri keeps looking in the old, now empty folder.

Expected behavior

Saving should succeed and the value should read back unchanged. movedirectory should update CONTENT_DIR to the new folder.

Errors and logs

From my Docker run (Python 3.10.22, configobj 5.0.8):

UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 78: ordinal not in range(128)

movedirectory before the fix:

UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 4132: ordinal not in range(128)
Kolibri will look for content in: /tmp/home/.kolibri/content

movedirectory after the fix:

Current content directory is /media/usb/Vidéos-2
Kolibri will look for content in: /media/usb/Vidéos-2

Environment

  • Kolibri: develop at fe298f54 (tested with 0.20.0a1 setup)
  • OS: Linux in Docker (python:3.10-slim), Python 3.10.22
  • Dependencies: configobj 5.0.8, Django 3.2.25, pytest 6.2.5
  • Installation: source checkout in Docker
  • Reproducible: always

Additional context

  • One-line fix in kolibri/utils/options.py: add encoding="utf-8" to ConfigObj(...) in read_options_file().
  • New test: test_option_writing_non_ascii_value in kolibri/utils/tests/test_options.py. It fails on develop and passes with the fix.
  • With the fix, kolibri/utils/tests/test_options.py gives 14 passed; related suites (kolibri/utils/tests, test_movedirectory.py, kolibri/core/device/test) give 796 passed, 2 skipped. On the original code the new test fails with UnicodeEncodeError.
  • If PR #15646 lands first, its new ConfigObj(conf.filename) line will also need encoding="utf-8"; the new test catches that.
  • I did not test on Windows, macOS, a real browser, Postgres, or the full test suite. GitHub CI will cover those.
  • I could not find an existing report for this.

AI usage

I used an AI assistant to help structure this report and set up the Docker reproduction. I ran the reproduction command myself, verified the output and logs above, and edited the final text. The claims here are from my own run.


Could a maintainer assign this issue to me if it is valid? I would like to work on the fix.

Darshanpawar7 avatar Nov 13 '26 13:11 Darshanpawar7

🔍 Thanks for opening this issue! @rtibblesbot will check it against the code and comment with its findings.

What happens next:

  • The community-issue-review label stays on until the review comment is posted.
  • The comment identifies the files, lines, or commits examined so you can follow the reasoning and respond if you disagree.
  • If the check confirms the issue, @rtibblesbot may also correct the title and description. GitHub preserves the edit history, so the original text remains available.
  • @rtibblesbot's comments are LLM-generated, so please evaluate them critically.

A maintainer decides what happens next. This check does not close the issue.

learning-equality-bot avatar Nov 13 '26 13:11 learning-equality-bot

Verdict: claim holds Evidence: kolibri/utils/options.py:1018 on develop at fe298f5449 builds ConfigObj(ini_path, configspec=get_configspec()) with no encoding; configobj 5.0.8 write() encodes with self.encoding or self.default_encoding or 'ascii'.

  • configobj 5.0.8 decodes a BOM-less file as UTF-8 when encoding is unset, so a non-ASCII value reads back fine.
  • update_options_file() (kolibri/utils/options.py:1124) rewrites the whole file via conf.write(), which raises UnicodeEncodeError once any value is non-ASCII, whichever key is being set.
  • Reproduced directly against configobj 5.0.8: an options.ini holding CONTENT_DIR = /media/usb/Vidéos reads back unchanged, then write() fails with 'ascii' codec can't encode character '\xe9'; with encoding="utf-8" the write succeeds and keeps the UTF-8 bytes.
  • Callers that hit it:
    • Device settings: primary_storage_location / secondary_storage_locations setters (kolibri/core/device/models.py:238, :246), fed by DeviceSettingsSerializer (kolibri/core/device/viewsets/device_settings.py:38-39).
    • content movedirectory: kolibri/core/content/management/commands/content.py:90-98 copies the databases and storage folders, deletes them from the source, then calls update_options_file (:135). When that call fails, the content has already moved but CONTENT_DIR still points to the old, empty folder, as the report states.
  • No existing issue reports this; the closest search hits (#6298, #3383) are about other encoding errors.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 13 '26 14:11 rtibblesbot