question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Evennia test raises RuntimeError after upgrade to django 3.2

See original GitHub issue

Describe the bug

I decided to finally see about maybe updating the version of Evennia I’m using for Arx. There were a few trivial changes to address deprecations, but a more serious issue is that the test runner completely refuses to function. After running through migrations for the test database and adding context types/permissions, I get the following error, which only touches library code:

Using settings file 'test_settings' (server.conf.test_settings).

    TESTING: Using specified settings file 'server.conf.test_settings'.

    OBS: Evennia's full test suite may not pass if the settings are very
    different from the default (use 'evennia test evennia' to run core tests)

Creating test database for alias 'default'...
Traceback (most recent call last):
  File "D:\arx\venv\Scripts\evennia_launcher.py", line 18, in <module>
    main()
  File "D:\arx\evennia\evennia\server\evennia_launcher.py", line 2282, in main
    sys.exit(execute_from_command_line(sys.argv))
  File "D:\arx\venv\Lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "D:\arx\venv\Lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\arx\venv\Lib\site-packages\django\core\management\commands\test.py", line 23, in run_from_argv
    super().run_from_argv(argv)
  File "D:\arx\venv\Lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\arx\venv\Lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "D:\arx\venv\Lib\site-packages\test_without_migrations\management\commands\_base.py", line 78, in handle
    super(CommandMixin, self).handle(*test_labels, **options)
  File "D:\arx\venv\Lib\site-packages\django\core\management\commands\test.py", line 55, in handle
    failures = test_runner.run_tests(test_labels)
  File "D:\arx\venv\Lib\site-packages\django\test\runner.py", line 725, in run_tests
    old_config = self.setup_databases(aliases=databases)
  File "D:\arx\venv\Lib\site-packages\django\test\runner.py", line 643, in setup_databases
    return _setup_databases(
  File "D:\arx\venv\Lib\site-packages\django\test\utils.py", line 179, in setup_databases
    connection.creation.create_test_db(
  File "D:\arx\venv\Lib\site-packages\django\db\backends\base\creation.py", line 90, in create_test_db
    self.connection._test_serialized_contents = self.serialize_db_to_string()
  File "D:\arx\venv\Lib\site-packages\django\db\backends\base\creation.py", line 136, in serialize_db_to_string
    serializers.serialize("json", get_objects(), indent=None, stream=out)
  File "D:\arx\venv\Lib\site-packages\django\core\serializers\__init__.py", line 129, in serialize
    s.serialize(queryset, **options)
  File "D:\arx\venv\Lib\site-packages\django\core\serializers\base.py", line 90, in serialize
    for count, obj in enumerate(queryset, start=1):
  File "D:\arx\venv\Lib\site-packages\django\db\backends\base\creation.py", line 125, in get_objects
    for model in app_config.get_models():
  File "D:\arx\venv\Lib\site-packages\django\apps\config.py", line 287, in get_models
    for model in self.models.values():
RuntimeError: dictionary changed size during iteration

To Reproduce

Steps to reproduce the behavior:

  1. Have a game with other apps/models
  2. run evennia test --settings=<your settings file here>
  3. See error

Expected behavior

The test runner to function the same as it did in django 2.12

Environment, Evennia version, OS etc

Evennia 0.9.5 (rev 8f916cb20) (rev 8f916cb20) OS: nt Python: 3.8.3 Twisted: 21.7.0 Django: 3.2.16

Additional context

My only running theory is that it might have something to do with how Evennia creates typeclasses, since they’re proxy models that aren’t fully registered. If you try to run makemigrations it’ll try to generate bogus migrations inside the evennia.typeclasses app. Possibly they could be mucking up the test database here in some way with some new change they made in django’s test runner in 3.2?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Griatchcommented, Nov 30, 2022

Closing this; we won’t accept any more changes to master branch, nor for Django 3.2.x.

1reaction
Griatchcommented, Oct 24, 2022

makemigrations without any arguments will try to create migrations for any typeclasses that a game creates, though you can avoid this by either manually deleting the migrations or only running app-specific migrations

Yes, we need to run app-specific makemigrations when adding custom tables exactly to avoid this. The Typeclass system is basically a hack on top of Django to extend the functionality of Proxy models and be able to treat them as quasi ‘real’ models for the purpose of searching and letting people not having to learn Django to make their own subclasses (with meta boilerplate etc). The drawback is that it fools Django migrations into thinking they should be considered.

Interesting that Django 4.x works for you, but not 3.2.x. I’ve not heard any other issues with that. Alas, Evennia 0.9.5 does not run on 4.x at this point so moving to develop or wait for 1.0 release would be the options in that case.

We can keep this open for now, in case someone else runs into it, but I don’t expect to be spending any time investigating this for master branch, so this sounds like it will not be addressed (at least not by me).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading to django 3.2 breaks API tests (response.data ...
It appears that in 3.2 after setting self.user.is_superuser = False the django backend will log the user out, thus resulting in ...
Read more >
Unit Testing — Evennia 0.9.5 documentation
Extensive testing helps avoid new updates causing unexpected side effects as well as alleviates general code rot (a more comprehensive wikipedia article on...
Read more >
evennia.utils.utils — Evennia 0.9.5 documentation
obj (any) – Entity to check for iterability. ... Raises. RuntimeError – If given invalid values. evennia.utils.utils. iter_to_string (initer, endsep='and', ...
Read more >
Updating Your Game — Evennia 0.9.5 documentation
Without installing/upgrading the package with -e , we would have to remember to upgrade the package every time we downloaded any new source-code...
Read more >
Evennia Devblog
I plan to pause the work on the new beginner tutorial and release 1.0 with that piece of the documentation unfinished. It still...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found