Ticket #323 (closed defect: invalid)

Opened 5 years ago

Last modified 4 years ago

Traceback when createing a new migration with ManyToMany field

Reported by: anonymous Owned by: andrew
Priority: minor Milestone: 0.7
Component: commands Version: 0.7-pre
Keywords: ManyToManyField Cc:

Description

looks like ticket #279

I used django 1.2-pre-alfa, but in latest trunk 1.2-alfa-1 (12295) this problem exist too.

D:\Projects\shadrinsk_info\src\shadrinsk_info>manage startmigration gazeta add_sitest_framework_support --auto
Traceback (most recent call last):
  File "D:\Projects\shadrinsk_info\src\shadrinsk_info\manage.py", line 11, in <module>
    execute_manager(settings)
  File "C:\Python25\Lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
    utility.execute()
  File "C:\Python25\Lib\site-packages\django\core\management\__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python25\lib\site-packages\django\core\management\base.py", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python25\lib\site-packages\django\core\management\base.py", line 222, in execute
    output = self.handle(*args, **options)
  File "C:\Python25\Lib\site-packages\south\management\commands\startmigration.py", line 237, in handle
    last_orm = migrations[-1].orm
  File "C:\Python25\Lib\site-packages\south\orm.py", line 62, in __get__
    self.orm = FakeORM(*self._args)
  File "C:\Python25\Lib\site-packages\south\orm.py", line 45, in FakeORM
    _orm_cache[args] = _FakeORM(*args)
  File "C:\Python25\Lib\site-packages\south\orm.py", line 106, in __init__
    self.models[name] = self.make_model(app_name, model_name, data)
  File "C:\Python25\Lib\site-packages\south\orm.py", line 308, in make_model
    fields,
  File "C:\Python25\Lib\site-packages\django\db\models\base.py", line 189, in __new__
    new_class._prepare()
  File "C:\Python25\Lib\site-packages\django\db\models\base.py", line 233, in _prepare
    signals.class_prepared.send(sender=cls)
  File "C:\Python25\lib\site-packages\django\dispatch\dispatcher.py", line 166, in send
    response = receiver(signal=self, sender=sender, **named)
  File "C:\Python25\Lib\site-packages\django\db\models\fields\related.py", line 82, in do_pending_lookups
    operation(field, sender, cls)
  File "C:\Python25\Lib\site-packages\django\db\models\fields\related.py", line 107, in resolve_related_class
    field.do_related_class(model, cls)
  File "C:\Python25\Lib\site-packages\django\db\models\fields\related.py", line 122, in do_related_class
    self.contribute_to_related_class(other, self.related)
  File "C:\Python25\Lib\site-packages\django\db\models\fields\related.py", line 1082, in contribute_to_related_class
    setattr(cls, related.get_accessor_name(), ManyRelatedObjectsDescriptor(related))
TypeError: attribute name must be string, not 'NoneType'

Change History

comment:1 Changed 5 years ago by andrew

  • Milestone set to 0.7

In my experience, this kind of thing is often a transitory bug as django trunk stablisies; nevertheless, I'll put it on the list to check for 0.7 before release.

comment:2 Changed 5 years ago by andrew

  • Status changed from new to assigned

comment:3 Changed 5 years ago by andrew

  • Priority changed from major to minor

comment:4 Changed 5 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to invalid

Can't replicate this; closing as invalid.

comment:5 Changed 4 years ago by thomas@…

I was working on a project today that had migrations created in the 0.6 days, and I think a came up with a way to reliably duplicate this bug:

Try creating a model with a self-referential ManyToMany? field:

class Tweet(models.Model):
	replies = models.ManyToManyField('Tweet', related_name='reply_to', null=True, blank=True)
'tweet_manager.tweet': {
     'replies': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['tweet_manager.Tweet']", 'null': 'True', 'blank': 'True'}),
     'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
}

Here's the traceback on migrating forward:

./manage.py migrate tweet_manager
Running migrations for tweet_manager:
 - Migrating forwards to 0003_set_created_locally_at_times_to_tw_creation_time.
 > tweet_manager:0001_initial
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_manager(settings)
  File "/Users/thomas/Library/Python/user-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/Users/thomas/Library/Python/user-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/thomas/Library/Python/user-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/thomas/Library/Python/user-packages/django/core/management/base.py", line 223, in execute
    output = self.handle(*args, **options)
  File "/Users/thomas/Library/Python/user-packages/south/management/commands/migrate.py", line 102, in handle
    delete_ghosts = delete_ghosts,
  File "/Users/thomas/Library/Python/user-packages/south/migration/__init__.py", line 177, in migrate_app
    success = migrator.migrate_many(target, workplan)
  File "/Users/thomas/Library/Python/user-packages/south/migration/migrators.py", line 210, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations)
  File "/Users/thomas/Library/Python/user-packages/south/migration/migrators.py", line 275, in migrate_many
    result = self.migrate(migration)
  File "/Users/thomas/Library/Python/user-packages/south/migration/migrators.py", line 119, in migrate
    result = self.run(migration)
  File "/Users/thomas/Library/Python/user-packages/south/migration/migrators.py", line 87, in run
    db.current_orm = self.orm(migration)
  File "/Users/thomas/Library/Python/user-packages/south/migration/migrators.py", line 235, in orm
    return migration.orm()
  File "/Users/thomas/Library/Python/user-packages/south/utils.py", line 56, in method
    value = function(self)
  File "/Users/thomas/Library/Python/user-packages/south/migration/base.py", line 397, in orm
    return FakeORM(self.migration_class(), self.app_label())
  File "/Users/thomas/Library/Python/user-packages/south/orm.py", line 46, in FakeORM
    _orm_cache[args] = _FakeORM(*args)  
  File "/Users/thomas/Library/Python/user-packages/south/orm.py", line 125, in __init__
    self.models[name] = self.make_model(app_label, model_name, data)
  File "/Users/thomas/Library/Python/user-packages/south/orm.py", line 344, in make_model
    fields,
  File "/Users/thomas/Library/Python/user-packages/django/db/models/base.py", line 193, in __new__
    new_class._prepare()
  File "/Users/thomas/Library/Python/user-packages/django/db/models/base.py", line 238, in _prepare
    signals.class_prepared.send(sender=cls)
  File "/Users/thomas/Library/Python/user-packages/django/dispatch/dispatcher.py", line 166, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/Users/thomas/Library/Python/user-packages/django/db/models/fields/related.py", line 82, in do_pending_lookups
    operation(field, sender, cls)
  File "/Users/thomas/Library/Python/user-packages/django/db/models/fields/related.py", line 107, in resolve_related_class
    field.do_related_class(model, cls)
  File "/Users/thomas/Library/Python/user-packages/django/db/models/fields/related.py", line 122, in do_related_class
    self.contribute_to_related_class(other, self.related)
  File "/Users/thomas/Library/Python/user-packages/django/db/models/fields/related.py", line 1082, in contribute_to_related_class
    setattr(cls, related.get_accessor_name(), ManyRelatedObjectsDescriptor(related))
TypeError: attribute name must be string, not 'NoneType'

I was getting this error when trying to migrate forward, not when the migration was being created like the original poster. In my case, the migration already existed because it was created with 0.6. Given the traceback similarities though, I'd guess that they're related issues.

south: trunk, latest (as of 3/19/2010)
django: trunk - r12807

I hope this information helps and thanks for all the hard work.

comment:6 Changed 4 years ago by andrew

Hrm, I just tried that here and it works fine. I think the problem in your case may be that you created with 0.6, which had a few issues.

Try putting this in the models entry under 'tweet_manager.tweet':

'Meta': {'object_name': 'Tweet'},

That's a new thing in 0.7, to solve issues related to capitalisation and these kinds of bugs.

Note: See TracTickets for help on using tickets.