jrief / djangocms-cascade

Build Single Page Applications using the Django-CMS plugin system
MIT License
165 stars 85 forks source link

Issues upgrading djangocms-cascade from 0.15.5 to 1.3.1 #386

Closed mandan closed 4 years ago

mandan commented 4 years ago

Hi,

We've had to stay pinned on a lower version of django-shop (< 0.12) for a long time due to changes in later versions breaking certain parts of our site. We've finally managed to set aside the time to upgrade to django-shop 1.1.4 and django 2.2. We've updated everything mostly successfully, but we're now running into issues with the 0027_version_1 migration from cmsplugin_cascade. In migrate_link, it expects a 'model' and 'pk' in glossary['link'], neither of which exist in any of the referenced cascade_element glossaries in our db.

What should we do?

Thanks, Vivek

jrief commented 4 years ago

Yes, between major version 0.x and 1.0 there unfortunately had to be a breaking change. This was caused by moving the JSON editor part out of djangocms-cascade into the django-entangled project, making it reusable to other projects.

This unfortunately required to restructure the JSON scheme in the glossary field. Could you please send me a list of JSON objects of your database model cmsplugin_cascade.cascade_element using Django's dumping fixtures feature. I then will have another look.

mandan commented 4 years ago

Email sent! Thanks!

jrief commented 4 years ago

Just had a look at your DB dump. In all occurrences of glossary['link'] with glossary['link']['type'] == 'cmspage', there is actually a model and pk. What exactly occurs when you apply that migration?

mandan commented 4 years ago

Hi Jacob,

The issue seems to be specifically with the one exturl cascadeelement that we have.

{
    "model": "cmsplugin_cascade.cascadeelement",
    "pk": 2213,
    "fields": {
        "glossary": "{\"link_content\": \"test\", \"link\": {\"url\": \"https://production.trustedstratus.com/account/login\", \"type\": \"exturl\"}, \"target\": \"\", \"render_template\": \"cascade/link/text-link.html\", \"title\": \"\"}",
        "shared_glossary": null
    }
},

The migration expects a model and pk inside of glossary['link'] for other types besides 'cmspage', but it doesn't exist in this case.

Here's the stack trace:

Traceback (most recent call last):
  File "./manage.py", line 29, in <module>
    main()
  File "./manage.py", line 25, in main
    execute_from_command_line(sys.argv)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/django/db/migrations/operations/special.py", line 190, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/cmsplugin_cascade/migrations/0027_version_1.py", line 77, in forwards
    changed = migrate_link(cascade_element.glossary) or changed
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/cmsplugin_cascade/migrations/0027_version_1.py", line 25, in migrate_link
    'ext_url': foreign_key(),
  File "/Users/vmandan/.virtualenvs/tss-p3d2m/lib/python3.7/site-packages/cmsplugin_cascade/migrations/0027_version_1.py", line 7, in foreign_key
    return {'model': link['model'].lower(), 'pk': link['pk']}
KeyError: 'model'
jrief commented 4 years ago

Thanks for informing about this. Shall be fixed in version 1.3.2.

mandan commented 4 years ago

Thank you, Jacob. I've tested this and it works for us.