Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Whoops. Need to be good and use six.

  • Loading branch information...
commit 941d23e54890bcc9e73734c5c1f3c82193fd97d6 1 parent ade34c4
@andrewgodwin andrewgodwin authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  django/db/models/fields/related.py
View
2  django/db/models/fields/related.py
@@ -958,7 +958,7 @@ def __init__(self, to, from_fields, to_fields, **kwargs):
def resolve_related_fields(self):
if len(self.from_fields) < 1 or len(self.from_fields) != len(self.to_fields):
raise ValueError('Foreign Object from and to fields must be the same non-zero length')
- if isinstance(self.rel.to, basestring):
+ if isinstance(self.rel.to, six.string_types):
raise ValueError('Related model %r cannot been resolved' % self.rel.to)
related_fields = []
for index in range(len(self.from_fields)):

1 comment on commit 941d23e

@max-arnold

With custom user model I get the following traceback when running any test:

Traceback (most recent call last):
  File "src/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
    super(Command, self).execute(*args, **options)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/test/runner.py", line 147, in run_tests
    old_config = self.setup_databases()
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/test/runner.py", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/test/runner.py", line 299, in setup_databases
    verbosity, autoclobber=not interactive)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/backends/creation.py", line 367, in create_test_db
    test_database=True)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/__init__.py", line 167, in call_command
    return klass.execute(*args, **defaults)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 145, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/migrations/executor.py", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/migrations/executor.py", line 94, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/migrations/migration.py", line 97, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 28, in database_forwards
    schema_editor.create_model(model)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/backends/schema.py", line 256, in create_model
    self.create_model(field.rel.through)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/backends/schema.py", line 182, in create_model
    definition, extra_params = self.column_sql(model, field)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/backends/schema.py", line 109, in column_sql
    db_params = field.db_parameters(connection=self.connection)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1707, in db_parameters
    return {"type": self.db_type(connection), "check": []}
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1698, in db_type
    rel_field = self.related_field
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1605, in related_field
    return self.foreign_related_fields[0]
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1367, in foreign_related_fields
    return tuple(rhs_field for lhs_field, rhs_field in self.related_fields)
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1354, in related_fields
    self._related_fields = self.resolve_related_fields()
  File "/Users/user/.virtualenvs/prj/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1339, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.rel.to)
ValueError: Related model 'auth.Group' cannot be resolved

Some debugging context:

   1339         if isinstance(self.rel.to, six.string_types):
-> 1340             raise ValueError('Related model %r cannot be resolved' % self.rel.to)
   1341         related_fields = []

ipdb> self.rel.to
'auth.Group'
ipdb> six.string_types
(<type 'basestring'>,)
ipdb> self.model
<class '__fake__.User_groups'>
Please sign in to comment.
Something went wrong with that request. Please try again.