defrex / django-encrypted-fields

This is a collection of Django Model Field classes that are encrypted using Keyczar.
MIT License
193 stars 60 forks source link

Not able to work with django-rest #13

Closed ghost closed 8 years ago

ghost commented 9 years ago

Hi, I am trying to encrypt the fields,

class BankDetails(models.Model):
    id              = models.AutoField(primary_key=True)
    bank_name       = EncryptedTextField()
    account_number  = EncryptedIntegerField()
    ifsc_code       = EncryptedIntegerField() 

I am using rest framework also, When I try to access the rest api, it throws an error TextField

Request Method: GET
Request URL: http://localhost.com:8000/bankdetails/

Django Version: 1.7.4
Python Version: 2.7.9
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'rest_framework.authtoken',
 'app',
 'djcelery',
 'kombu.transport.django')
Installed Middleware:
(
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "C:\Users\YuO\project\www\lib\site-packages\django-1.7.4-py2.7.egg\django\core\handlers\base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\YuO\project\www\lib\site-packages\django-1.7.4-py2.7.egg\django\views\decorators\csrf.py" in wrapped_view
  57.         return view_func(*args, **kwargs)
File "C:\Users\YuO\project\www\lib\site-packages\django-1.7.4-py2.7.egg\django\views\generic\base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\views.py" in dispatch
  407.             response = self.handle_exception(exc)
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\views.py" in dispatch
  404.             response = handler(request, *args, **kwargs)
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\generics.py" in get
  311.         return self.list(request, *args, **kwargs)
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\mixins.py" in list
  46.         return Response(serializer.data)
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\serializers.py" in data
  615.         ret = super(ListSerializer, self).data
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\serializers.py" in data
  212.                 self._data = self.to_representation(self.instance)
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\serializers.py" in to_representation
  565.             self.child.to_representation(item) for item in iterable
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\serializers.py" in to_representation
  419.         fields = [field for field in self.fields.values() if not field.write_only]
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\serializers.py" in fields
  312.             for key, value in self.get_fields().items():
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\serializers.py" in get_fields
  1006.                 kwargs = get_field_kwargs(field_name, model_field)
File "C:\Users\YuO\project\www\lib\site-packages\djangorestframework-3.0.5-py2.7.egg\rest_framework\utils\field_mapping.py" in get_field_kwargs
  70.     validator_kwarg = list(model_field.validators)
File "C:\Users\YuO\project\www\lib\site-packages\django-1.7.4-py2.7.egg\django\utils\functional.py" in __get__
  55.         res = instance.__dict__[self.func.__name__] = self.func(instance)
File "C:\Users\YuO\project\www\lib\site-packages\django-1.7.4-py2.7.egg\django\db\models\fields\__init__.py" in validators
  1590.         min_value, max_value = connection.ops.integer_field_range(internal_type)
File "C:\Users\YuO\project\www\lib\site-packages\django-1.7.4-py2.7.egg\django\db\backends\__init__.py" in integer_field_range
  1334.         return self.integer_field_ranges[internal_type]

Exception Type: KeyError at /bankdetails/
Exception Value: 'TextField'
LigorioSalgado commented 8 years ago

You can resolve this??

ghost commented 8 years ago

I was not able to resolve it.

defrex commented 8 years ago

Sorry I got busy and forgot about this. If you could create a simple case to reproduce the issue, it'd help me out a lot being able to debug it.

mattijohn commented 8 years ago

I think this was fixed on master with https://github.com/defrex/django-encrypted-fields/issues/7, but the version on pypi (1.1.1) doesn't seem to include the fix.

defrex commented 8 years ago

I've just pushed the latest version to PyPi. Let me know if this issue persists.