Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sommelon opened this issue Apr 14, 2021 · 1 comment · Fixed by #14
Closed

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

sommelon opened this issue Apr 14, 2021 · 1 comment · Fixed by #14

Comments

@sommelon
Copy link
Contributor

sommelon commented Apr 14, 2021

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
@sommelon sommelon changed the title Migrator doesn't retain NULL values Migrator converts NULL values to a string "None" Apr 14, 2021
sommelon added a commit to sommelon/django-mirage-field that referenced this issue Apr 14, 2021
tcitry added a commit that referenced this issue Apr 15, 2021
fix #13: Fixed Migrator converting NULL values to a string 'None'
@tcitry
Copy link
Member

tcitry commented Apr 15, 2021

@sommelon Much thanks for the PR, I have upload to pypi with 1.1.8 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants