Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31592 closed Bug (invalid)

Reverting Django 3.1. to Django 3.0.6 raises "binascii.Error: Incorrect padding".

Reported by: אורי Owned by: nobody
Component: Core (Other) Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I upgraded to Django 3.1a1 and ran migrations. I also created my own migration because of the change from from django.contrib.postgres.fields import JSONField to from django.db.models import JSONField. My own migration was generated automatically:

# Generated by Django 3.1a1 on 2020-05-14 16:25

from django.db import migrations, models
import speedy.match.accounts.models


class Migration(migrations.Migration):

    dependencies = [
        ('match_accounts', '0006_auto_20200121_1731'),
    ]

    operations = [
        migrations.AlterField(
            model_name='siteprofile',
            name='diet_match',
            field=models.JSONField(default=speedy.match.accounts.models.SiteProfile.diet_match_default, verbose_name='Diet match'),
        ),
        migrations.AlterField(
            model_name='siteprofile',
            name='relationship_status_match',
            field=models.JSONField(default=speedy.match.accounts.models.SiteProfile.relationship_status_match_default, verbose_name='Relationship status match'),
        ),
        migrations.AlterField(
            model_name='siteprofile',
            name='smoking_status_match',
            field=models.JSONField(default=speedy.match.accounts.models.SiteProfile.smoking_status_match_default, verbose_name='Smoking status match'),
        ),
    ]

Most of the things worked with Django 3.1a1 except a few things which I will report later. But when trying to use Django 3.0.6 again, I ran the following commands:

./manage_all_sites.sh migrate auth 0011
./manage_all_sites.sh migrate match_accounts 0006

Then, after running my websites with Django 3.0.6, I received an error message:

Incorrect padding

I can't run my websites locally without deleting the database completely including all users. I didn't find any way to fix the database to run it with Django 3.0.6.

Change History (5)

comment:1 by אורי, 4 years ago

Summary: Can't revert to Django 3.0.6 after running migration for 3.1a1Can't revert to Django 3.0.6 after running migrations for 3.1a1

comment:2 by Mariusz Felisiak, 4 years ago

Component: UncategorizedCore (Other)
Resolution: invalid
Status: newclosed
Summary: Can't revert to Django 3.0.6 after running migrations for 3.1a1Reverting Django 3.1. to Django 3.0.6 raises "binascii.Error: Incorrect padding".

Thanks for this ticket. This error is not related with migrations but with sessions and changes of a hashing algorithm from the SHA-1 to SHA-256:

  File "django/contrib/sessions/backends/base.py", line 110, in decode
    encoded_data = base64.b64decode(session_data.encode('ascii'))
  File "python3.6/base64.py", line 87, in b64decode
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

To fix this you need to remove sessions from cache, e.g.

from django.contrib.sessions.models import Session
Session.objects.all().delete()

comment:3 by אורי, 4 years ago

Does this error also occur if I migrate forward (from 3.0 to 3.1) or only backwards?

Anyway, I think Django should be able to delete the relevant cache when migrating (backwards or forward) and not just raise exceptions which don't make sense to the users. Maybe just check the version of the session objects and if it's not correct then delete them.

comment:4 by אורי, 4 years ago

Also, does it mean migrating from Django 3.0 to 3.1 will log out all the users? I use persistent cookies for 30 years and I don't want to log out users who didn't log out or delete their cookies.

in reply to:  3 comment:5 by Mariusz Felisiak, 4 years ago

Replying to אורי:

Does this error also occur if I migrate forward (from 3.0 to 3.1) ...?

No, support for user sessions that use the old hashing algorithm remains until Django 4.0, see release notes.

Note: See TracTickets for help on using tickets.
Back to Top