-
Notifications
You must be signed in to change notification settings - Fork 50
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
Heroku and block_type='MODE_CBC' causes errors #41
Comments
I digged into the sources of pycrypto and found that there is very heavy lifting behind the atfork. Don't think it is a good idea to call it before any call to crypto library. Are there any hooks in celery to call atfork when worker was started? |
Yeah both Django and Celery have hooks for this, but it would mean django-fields by default doesn't work when you use Heroku/similar platforms or Celery. Plus passing this along as an optional argument to the field would be nicer as this would fix the issue in one place instead of all over the codebase (for everything that works threaded a seperate fix, maybe even without hooks to attach to). Either way the docs should be updated to mention this I think. |
As I understand threaded model is not affected. This issue is related to forked execution. |
I'm facing the same issue too with Heroku. What did you end up doing to resolve this? |
At the bottom of your wsgi.py (but as of django 1.7 this could go in apps.py)
Somewhere in your tasks.py:
|
As per the recommendation in the source code we switched to block_type='MODE_CBC' for our encrypted fields, only to get the following error:
Which is thrown by the Crypto library. After some googling around it seems this problem occurs when that library is used in combination with threading. So for example Celery and Heroku.
It is quite easy to fix, just call the Random.atfork() function before using Random in BaseEncryptedField (fields.py line 55 & 111).
The text was updated successfully, but these errors were encountered: