jazzband / django-oauth-toolkit

OAuth2 goodies for the Djangonauts!
https://django-oauth-toolkit.readthedocs.io
Other
3.16k stars 793 forks source link

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

Closed acidtv closed 3 weeks ago

acidtv commented 3 weeks ago

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

n2ygk commented 3 weeks ago

Sounds good. A PR to implement this would be appreciated.

acidtv commented 3 weeks ago

@n2ygk Good. I've made a pull request.