shaokun
shaokun

Reputation: 31

Django Unittest failing to run with TypeError: isinstance() arg 2 must be a type or tuple of types on one machine but not others

For some reason I cannot run "manage.py test AppNameHere" on my Windows machine but when I run it on a linux machine (I'm not sure if the OS actually matters here) the tests run fine. I am getting this error:

2019-01-11 17:35:32 [DEBUG] faker.factory: Not in REPL -> leaving logger event level as is.
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 22, in 
    execute_from_command_line(sys.argv)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\test.py", line 26, in run_from_argv
    super().run_from_argv(argv)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\test.py", line 56, in handle
    failures = test_runner.run_tests(test_labels)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\test\runner.py", line 604, in run_tests
    old_config = self.setup_databases()
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\test\runner.py", line 551, in setup_databases
    self.parallel, **kwargs
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\test\utils.py", line 174, in setup_databases
    serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\base\creation.py", line 68, in create_test_db
    run_syncdb=True,
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 148, in call_command
    return command.execute(*args, **defaults)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards
    field,
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 309, in add_field
    self._remake_table(model, create_field=field)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 181, in _remake_table
    self.effective_default(create_field)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\base\schema.py", line 218, in effective_default
    default = field.get_default()
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\fields\related.py", line 927, in get_default
    if isinstance(field_default, self.remote_field.model):
TypeError: isinstance() arg 2 must be a type or tuple of types

This looks like something is wrong with Django but I'm not sure. Does anyone have any insights on this? I don't want to go in modifying any of these files from the trace since they are a part of Django.

Upvotes: 2

Views: 796

Answers (3)

vinchuli
vinchuli

Reputation: 545

Another major cause of such issue is defining or assigning a none existing OneToOneField or ForeignkeyField. Just confirm in your model instance if all your relationships have exisiting model

Upvotes: 0

shaokun
shaokun

Reputation: 31

I solved this by:

  • deleting all my migration files
  • removing the entries in the django_migrations table
  • remade migrations (makemigrations)
  • did a migrate --fake

Upvotes: 1

Shekhar Koirala
Shekhar Koirala

Reputation: 186

what about changing the code File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\fields\related.py", line 927, in get_default

if isinstance(field_default, type(self.remote_field.model)):

Upvotes: 0

Related Questions