Skip to content

Migrator converts NULL values to a string "None" #13

@sommelon

Description

@sommelon

Hi.
I am using SQLite 3 and I have this model

class AuthConfig(models.Model):
   username = fields.EncryptedCharField(max_length=150, null=True, blank=True, verbose_name=_("Username"))
   password = fields.EncryptedCharField(null=True, blank=True, max_length=150, verbose_name=_("Password"))
   token = fields.EncryptedCharField(max_length=1500, null=True, blank=True, verbose_name=_("Token"))

My migration looks like this

migrations.RunPython(
    Migrator("integrations", "AuthConfig", "username").encrypt, reverse_code=Migrator("integrations", 'AuthConfig', 'username').decrypt
        ),
migrations.RunPython(
    Migrator("integrations", "AuthConfig", "password").encrypt, reverse_code=Migrator("integrations", 'AuthConfig', 'password').decrypt
        ),
migrations.RunPython(
    Migrator("integrations", "AuthConfig", "token").encrypt, reverse_code=Migrator("integrations", 'AuthConfig', 'token').decrypt
),

When the original field value is saved in the database as NULL, applying the migration will change the value to a string "None" because of the string interpolation used to construct an UPDATE statement in Migrators execute() method.

To reproduce:

  1. Make a model with an optional field (null=True)
  2. Create a record with that field being NULL
  3. Convert the field to an Encrypted field
  4. Run the migration with Migrator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions