jazzband / django-fernet-encrypted-fields

MIT License
42 stars 9 forks source link

I got KeyError: TextField when I tried using EncryptedIntegerField #10

Closed Ali-Javanmardi closed 2 years ago

Ali-Javanmardi commented 2 years ago

Hi,

I was developing a reusable-applications to use in my projects. I decided to encrypt some IntegerFields by using EncryptedIntegerField from django-fernet-encrypted-fields

So then when I tried to test my app by tox I got this error:

".tox/py310-4.0/lib/python3.10/site-packages/django/db/backends/base/operations.py", line 673, in integer_field_range return self.integer_field_ranges[internal_type]

KeyError: 'TextField'

As you can see in the error message I'm using python 3.10 and django 4.0.4

I searched for this error and I found a similar problem in django-cryptography project in the issue #16

The suggested solution there was using a DecimalField with decimal_place=0 instead of an IntegerField

I hope there is a possible solution to use IntegerField as I'm trying to keep integer data in my model.

frgmt commented 2 years ago

@Ali-Javanmardi Thanks for the info. Can you tell us specifically the cases you have tried?

Ali-Javanmardi commented 2 years ago

@frgmt Thanks to your early response,

As I mentioned before I did not anything special. Just created an empty Django application (no project) and tried to use django-fernet-encrypted-fields to encryp my data.

As I found I can use EncryptedCharField with no problem, but when I try to use EncryptedIntegerField and try to test it by tox I will receive this error:

File "/home/__/dev/try_encrypted_fields/.tox/py310-dj40/lib/python3.10/site-packages/django/db/backends/base/operations.py", line 673, in integer_field_range return self.integer_field_ranges[internal_type] KeyError: 'TextField' ERROR: InvocationError for command /home/__/dev/try_encrypted_fields/.tox/py310-dj40/bin/python make_migrations.py (exited with code 1) _______________________________________________________________________________ summary _______________________________________________________________________________ ERROR: py310-dj40: commands failed

so I made a test project here to simulate this error. If you try my test project you will find an EncryptedCharField that works and tox show no error by that.

But if you un-comment the other field with EncryptedIntegerField and try tox again you should receive error same as me.

I hope this helps to clear problem.

Thanks again,

Ali-Javanmardi commented 2 years ago

@frgmt just as a hint please note that error occurs when it tries to create migration file.

So I think that is the reason you had no error in your test before. I think in your test you did not makemigrations