Skip to content

Instantly share code, notes, and snippets.

@chosak
Created May 3, 2019 20:07
Show Gist options
  • Save chosak/55ec581af4260d13be13570d19a83027 to your computer and use it in GitHub Desktop.
Save chosak/55ec581af4260d13be13570d19a83027 to your computer and use it in GitHub Desktop.
PyCon US 2019 Wagtail open session

We had a nice open session this afternoon at PyCon US, organized by Sean Harrison from Caktus Group. There were about 15 people in the room. The session agenda was generally to discuss improving Wagtail for developers.

StreamField data migrations

Adding fields or blocks won't cause problems as long as you don't rename or removing anything.

Sean presented a nice multi-step approach that he recommends when migrating StreamFields. This way you can run each step independently and verify that it worked correctly.

  1. First add the new field or block (example).
  2. Make a migration that copies the data from old fields to new fields, but don't remove anything yet (example).
    • You need to iterate over all pages and all revisions of those pages.
    • It helps to use page.to_json() and process both page and revision JSON in the same way.
    • Wagtail documentation currently doesn't really cover how to do this.
    • Attendees agreed that it would be convenient if the Wagtail codebase included some utility functions to help with this, for example something like this from Sean's example.
    • CFPB has implemented a very similar approach to Caktus, documented here.
    • We mentioned the currently open Wagtail PR #4755 which is an attempt to add programmatic support for StreamField migrations.
  3. Let editors review migrated pages to verify that everything looks good, before removing anything.
  4. Delete old fields (example).

Vince Salvino from CodeRed CMS talked a bit about some problems with the large migration files that can be generated when StreamFields are changed.

We mentioned Wagtail issue #4298 which discusses some ways of reducing migration file size. It's also interesting to consider whether StreamField block structure really needs to be persisted to the migration files.

wagtail-import-export

Sean discussed his fork of wagtail-import-export.

He has an open PR that adds support for exporting/importing of images and snippets along with pages. It's a tricky problem to re-map IDs when importing. Caktus uses page URLs as the identifier for pages, and we talked about how since 2.2 Wagtail has file_hash that can be used for documents and images.

StreamField documentation

We briefly discussed that the current StreamField documentation is overdue for a rewrite:

It's a single giant page, and hard to find the information you need. It doesn't cover all use cases, for example migrations as mentioned above. It would be nice to refactor this into several different pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment