Ticket #1142 (closed defect: invalid)

Opened 2 years ago

Last modified 2 years ago

__init__() takes at least 2 arguments (1 given) When Migrating using South with Custom Fields

Reported by: fady.kamal@… Owned by: andrew
Priority: major Milestone:
Component: migrations Version: 0.7.5
Keywords: Cc:

Description

i am new to south and i followed their documentation and after initializing south migrations, after running

manage.py migrate appname
for the following custom models Models i added introspection rules as follows

Models:

class DependentIntegerField?(models.IntegerField?):

def init(self, default_callable, *args, kwargs):

self.default_callable = default_callable
super(DependentIntegerField?, self).init(*args, kwargs)

def pre_save(self, model_instance, add):

if not add:

return super(DependentIntegerField?, self).pre_save(model_instance, add)

return self.default_callable(model_instance)

class Level(models.Model):

group = models.ForeignKey?(Level_Group)
number = models.IntegerField?(unique=True)#null=True, blank=True
threshold = DependentIntegerField?(lambda mi:mi.number*50,null=False,blank=True)

def str(self):

return '%s' %(self.number)

def get_fib(self):

return fib(self.number+3)

class Gallery (models.Model):

contractor = models.ForeignKey?(Contractor)
image = StdImageField?(upload_to='GalleryDB', size=(640, 480,True))
Title = models.CharField?(max_length=250,null=True,blank = True)
Caption = models.CharField?(max_length=1000,null=True,blank=True)

Introspection Rules :

add_introspection_rules([

(

[Level], # Class(es) these apply to
[], # Positional arguments (not used)
{ # Keyword argument

"threshold": ["threshold", {}],

},

),

], ^shoghlanah\.models\.DependentIntegerField?)

add_introspection_rules([

(

[Gallery], # Class(es) these apply to
[], # Positional arguments (not used)
{ # Keyword argument

"image": image?, "upload_to": GalleryDB?

},

),

], ^stdimage\.fields\.StdImageField?)
Traceback

Traceback (most recent call last):

File "manage.py", line 10, in <module>

execute_from_command_line(sys.argv)

File "/Library/Python?/2.7/site-packages/django/core/management/init.py", line 443, in execute_from_command_line

utility.execute()

File "/Library/Python?/2.7/site-packages/django/core/management/init.py", line 382, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)

File "/Library/Python?/2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv

self.execute(*args, options.dict)

File "/Library/Python?/2.7/site-packages/django/core/management/base.py", line 232, in execute

output = self.handle(*args, options)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/management/commands/migrate.py", line 107, in handle

ignore_ghosts = ignore_ghosts,

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/migration/init.py", line 219, in migrate_app

success = migrator.migrate_many(target, workplan, database)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/migration/migrators.py", line 235, in migrate_many

result = migrator.class.migrate_many(migrator, target, migrations, database)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/migration/migrators.py", line 310, in migrate_many

result = self.migrate(migration, database)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/migration/migrators.py", line 133, in migrate

result = self.run(migration)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/migration/migrators.py", line 99, in run

south.db.db.current_orm = self.orm(migration)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/migration/migrators.py", line 260, in orm

return migration.orm()

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/utils/init.py", line 62, in method

value = function(self)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/migration/base.py", line 427, in orm

return FakeORM(self.migration_class(), self.app_label())

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/orm.py", line 45, in FakeORM

_orm_cache[args] = _FakeORM(*args)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/orm.py", line 124, in init

self.models[name] = self.make_model(app_label, model_name, data)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/orm.py", line 317, in make_model

field = self.eval_in_context(code, app, extra_imports)

File "/Library/Python?/2.7/site-packages/South-0.7.5-py2.7.egg/south/orm.py", line 235, in eval_in_context

return eval(code, globals(), fake_locals)

File "<string>", line 1, in <module>

TypeError?: init() takes at least 2 arguments (1 given)
i am little sure it's from the field DependentIntegerField? but i don't know which init is it trying to call and i tried

"threshold": ["threshold", {"ldefault_callable":default_callable}],
but i get

NameError?: name 'default_callable' is not defined

Change History

comment:1 Changed 2 years ago by andrew

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

Not a bug in South (there's a discussion about this on the mailing list already).

Note: See TracTickets for help on using tickets.