Skip to content

Migration oauth2_provider.0012_add_token_checksum does not work for large access token tables #1521

@acidtv

Description

@acidtv

Describe the bug
In 3.0.0 the oauth2_provider.0012_add_token_checksum migration was added to add a new column to the access token table. This migration upgrades the table by looping over AccessToken._default_manager.all() which causes the entire table to be loaded in memory.

https://github.com/jazzband/django-oauth-toolkit/blob/907d70f08c1bef94a485bde8fd3edb51952aec03/oauth2_provider/migrations/0012_add_token_checksum.py#L12-L14

This does not work for systems with limited memory and large access token tables because the migrate process will be killed by the OOM killer.

This could be fixed by using an iterator: AccessToken._default_manager.iterator()

To Reproduce
Run ./manage.py migrate on a system with a large access token table.

Expected behavior
A successful migration.

Version
3.0.1

  • I have tested with the latest published release and it's still a problem.
  • I have tested with the master branch and it's still a problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions