No multi-process support
kevcampb opened this issue · 4 comments
It seems that django-select2 is dependent on two global dictionaries for the autoselect fields. The following are in django_select2/util.py
# Generated Id to field instance mapping.
__id_store = {}
# Field's key to generated Id mapping.
__field_store = {}
Obviously this is going to fail when you run multi-process. Not sure what would be involved in getting multi-process support, and whether these details could be written back into SQL. That may be a feature request, although breaking multi-process support is certainly a huge issue.
At the very least this should be highlighted on the front page of the manual, so people are aware of the limitation before bringing this library in.
This was on my Todo list. Sorry for not pointing that out in Readme. You can still use this library in multi-proceses scenario if do not use Auto fields.
Let me checkout the options. I guess I will use memcache for multi-process support in Auto fields.
Supported added in version 3.3.0.
Shouldn't there be something more easier for unique ids instead of a this syncronization via memcache? I guess, python path for each of a autocomplete classes is unique enough and we can just use it for a field id.
I'm using that scheme and it works for me:
https://github.com/svartalf/django-select2/commit/60f707f775d211417c06865498268e40f47df78d
The reason I chose the random id approach since that way no outsider (outside of server, a typical user) can guess the path of the field. Since field names and their paths reveal a lot of inside information so I consider that information sensitive.
Hashing the path too is a novel approach but they are not impossible to crack. However, I do recognize the fact that maybe for 90% of the users your approach would suffice. Particularly when that rids us of the need to use Memcache.
So, I will incorporate your changes and make that the default. The current random id approach will remain there which can be turned on if needed.