Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordinal not in range #82

Open
kgilpin opened this issue Oct 28, 2024 · 1 comment
Open

Ordinal not in range #82

kgilpin opened this issue Oct 28, 2024 · 1 comment

Comments

@kgilpin
Copy link
Contributor

kgilpin commented Oct 28, 2024

https://github.com/getappmap/navie-benchmark/actions/runs/11544982873/job/32131260977#step:7:449

error: patch with only garbage at line 3
Creating test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')\u2026
Testing against Django installed in '/testbed/django'
Importing application aggregation_regress
Skipping setup of unused database(s): other.
Operations to perform:
  Synchronize unmigrated apps: aggregation_regress, auth, contenttypes, messages, sessions, staticfiles
  Apply all migrations: admin, sites
Synchronizing apps without migrations:
Traceback (most recent call last):
  File "./tests/runtests.py", line 503, in <module>
    options.exclude_tags,
  File "./tests/runtests.py", line 290, in django_tests
    extra_tests=extra_tests,
  File "/testbed/django/test/runner.py", line 629, in run_tests
    old_config = self.setup_databases(aliases=databases)
  File "/testbed/django/test/runner.py", line 554, in setup_databases
    self.parallel, **kwargs
  File "/testbed/django/test/utils.py", line 174, in setup_databases
    serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
  File "/testbed/django/db/backends/base/creation.py", line 72, in create_test_db
    run_syncdb=True,
  File "/testbed/django/core/management/__init__.py", line 148, in call_command
    return command.execute(*args, **defaults)
  File "/testbed/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/testbed/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/testbed/django/core/management/commands/migrate.py", line 203, in handle
    self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/testbed/django/core/management/commands/migrate.py", line 324, in sync_apps
    self.stdout.write("  Creating tables\u2026\n")
  File "/testbed/django/core/management/base.py", line 145, in write
    self._out.write(style_func(msg))
UnicodeEncodeError: 'ascii' codec can't encode character '\u2026' in position 17: ordinal not in range(128)
Copy link

Title: Resolve "Ordinal Not in Range" Error in Django Test Output

Problem: When running tests with Django, a UnicodeEncodeError occurs, indicating that an ASCII codec cannot encode the character at position 17. The presence of a Unicode character (\u2026, which is an ellipsis) in the text output of stdout is triggering the error, as the ASCII codec doesn't support characters beyond the 128 ordinal range.

Analysis: The error stems from the attempt to write a Unicode character (ellipsis ) to an output stream that is encoded in ASCII. This typically happens when developing on systems with limited locale support or when the Unicode-to-ASCII conversion is not handled properly by the program. The error suggests that Django's output mechanism is encountering a character that it is unable to process due to ASCII encoding limitations.

The root cause is the use of Unicode characters where ASCII handling is expected. This usually occurs in two situations:

  1. The system default encoding does not support Unicode, and therefore falls back to ASCII.
  2. The handling of strings in Django's commands or during test execution does not properly use a Unicode-compatible output stream.

Proposed Changes:

  1. Correct Encoding Configuration:

    • Ensure the environment in which Django tests are run supports UTF-8 encoding. This might mean setting environment variables or ensuring the console can display and process UTF-8 characters.
  2. Modify Django's Output Mechanism:

    • File: /testbed/django/core/management/base.py:
      • Modify the write method of the base management command class to ensure it uses a Unicode-aware stream (like UTF-8) or introduces error handling to safely replace or ignore non-ASCII characters.
  3. Review Environment and Locale Settings:

    • Double-check the environment settings used during the testing process. Ensure that the locale and language settings favor UTF-8 to provide proper Unicode support. This includes settings in CI/CD environments when tests are automated.
  4. Test and Validate:

    • After implementing the changes, rerun the tests to confirm that the UnicodeEncodeError is resolved. Make sure that no other parts of the code are adversely affected by these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant