Opened 10 years ago

Last modified 10 years ago

#23851 closed Bug

'GenericForeignKey' object has no attribute 'deconstruct' — at Version 7

Reported by: corebreaker Owned by: nobody
Component: contrib.contenttypes Version: 1.7
Severity: Normal Keywords:
Cc: corebreaker Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by corebreaker)

The class django.contrib.contenttypes.generic.GenericForeignKey is a field type for models, used for my example by application cmsplugin_rt.rt_carousel, application that i modified in order to use it in Django 1.7 .

But class django.contrib.contenttypes.generic.GenericForeignKey has not the required method deconstruct.

I posted this ticket cause class django.contrib.contenttypes.generic.GenericForeignKey could be used by others as field in models and the exception could be raised for this reason.

The lack is just that class django.contrib.contenttypes.generic.GenericForeignKey has not implemented the required method deconstruct. This method should be added if not, we have to subclass GenericForeignKey at every time we use it as field in models. It's just a big work to do each time.

Change History (8)

comment:1 by corebreaker, 10 years ago

Severity: Release blockerNormal

comment:2 by corebreaker, 10 years ago

Cc: corebreaker added
Type: UncategorizedBug

comment:3 by corebreaker, 10 years ago

Description: modified (diff)

comment:4 by corebreaker, 10 years ago

Description: modified (diff)

comment:5 by Baptiste Mispelon, 10 years ago

Hi,

How do you get that error message?
From what I've tried, using a GenericForeignKey in a model works with migrations and doesn't trigger any particular error.

Thanks.

by corebreaker, 10 years ago

Attachment: formbug.zip added

Django 1.7 project simple example that shows the bug.

comment:6 by corebreaker, 10 years ago

I joined a Django project that has the bug. Use migrate command to see it. The result is:

Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages
  Apply all migrations: admin, contenttypes, formbug, auth, sessions
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying formbug.0001_initial...Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 160, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 63, in migrate
    self.apply_migration(migration, fake=fake)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 91, in apply_migration
    if self.detect_soft_applied(migration):
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 135, in detect_soft_applied
    apps = project_state.render()
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/state.py", line 67, in render
    model.render(self.apps)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/state.py", line 305, in render
    body = dict(self.construct_fields())
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/state.py", line 276, in construct_fields
    _, path, args, kwargs = field.deconstruct()
AttributeError: 'GenericForeignKey' object has no attribute 'deconstruct'

I just used GenericForeignKey class as a model field. In Django 1.7, model fields require to implement deconstruct method. But GenericForeignKey has not implemented this method.

Last edited 10 years ago by corebreaker (previous) (diff)

comment:7 by corebreaker, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top