#24308 closed Bug (invalid)
ValueError: Cannot serialize: <bound method SiteManager.get_current of <django.contrib.sites.models.SiteManager object at 0xb647c9ac>>
Reported by: | jedie | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.7 |
Severity: | Normal | Keywords: | MigrationWriter, Site |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Traceback (most recent call last): File "./manage.py", line 13, in <module> execute_from_command_line(sys.argv) File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line utility.execute() File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute output = self.handle(*args, **options) File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/core/management/commands/makemigrations.py", line 124, in handle self.write_migration_files(changes) File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/core/management/commands/makemigrations.py", line 152, in write_migration_files migration_string = writer.as_string() File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/migrations/writer.py", line 131, in as_string operation_string, operation_imports = OperationWriter(operation).serialize() File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/migrations/writer.py", line 82, in serialize arg_string, arg_imports = MigrationWriter.serialize(item) File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/migrations/writer.py", line 263, in serialize item_string, item_imports = cls.serialize(item) File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/migrations/writer.py", line 333, in serialize return cls.serialize_deconstructed(path, args, kwargs) File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/migrations/writer.py", line 239, in serialize_deconstructed arg_string, arg_imports = cls.serialize(arg) File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/db/migrations/writer.py", line 409, in serialize "topics/migrations/#migration-serializing" % value ValueError: Cannot serialize: <bound method SiteManager.get_current of <django.contrib.sites.models.SiteManager object at 0xb647c9ac>> There are some values Django cannot serialize into migration files. For more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing
one up with Pdb:
(Pdb) l 328 elif isinstance(value, decimal.Decimal): 329 return repr(value), set(["from decimal import Decimal"]) 330 # Django fields 331 elif isinstance(value, models.Field): 332 attr_name, path, args, kwargs = value.deconstruct() 333 -> return cls.serialize_deconstructed(path, args, kwargs) 334 # Classes 335 elif isinstance(value, type): 336 special_cases = [ 337 (models.Model, "models.Model", []), 338 ] (Pdb) a cls = <class 'django.db.migrations.writer.MigrationWriter'> value = <django.db.models.fields.related.ForeignKey: site> {{{ one Up again: {{{ (Pdb) l 234 for arg in args: 235 arg_string, arg_imports = cls.serialize(arg) 236 strings.append(arg_string) 237 imports.update(arg_imports) 238 for kw, arg in kwargs.items(): 239 -> arg_string, arg_imports = cls.serialize(arg) 240 imports.update(arg_imports) 241 strings.append("%s=%s" % (kw, arg_string)) 242 return "%s(%s)" % (name, ", ".join(strings)), imports 243 244 @classmethod (Pdb) a cls = <class 'django.db.migrations.writer.MigrationWriter'> path = 'django.db.models.ForeignKey' args = [] kwargs = {'default': <bound method SiteManager.get_current of <django.contrib.sites.models.SiteManager object at 0xb647c9ac>>, 'to': 'sites.Site'} }}} }}}
Change History (2)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
As pointed out in the traceback you should refer to the documentation.
Due to the fact __qualname__ was only introduced in Python 3, Django can only serialize the following pattern (an unbound method used within the class body) on Python 3, and will fail to serialize a reference to it on Python 2:
If you are using Python 2, we recommend you move your methods for upload_to and similar arguments that accept callables (e.g. default) to live in the main module body, rather than the class body.
Note:
See TracTickets
for help on using tickets.
Ah, seems that this is the trigger for this:
I change this to: