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

Assumption that user.id is an int, but this breaks when using django-nonrel #103

Open
csmaster2005 opened this issue Dec 17, 2013 · 3 comments
Milestone

Comments

@csmaster2005
Copy link

djangouser-accounts seems to work very well with django-nonrel (a version of django that works with non-relational database such as monogdb), except I noticed when trying to wire up the forgot-password, an exception is thrown (see below)

This seems like a straightforward fix. The reason it breaks is because in non-relational databases, the PK is not guranteed to be an int. In fact, it's usually more of a guid that is a combination of letters and characters.

File "/home/person/testenv2/local/lib/python2.7/site-packages/account/views.py", line 515, in send_email
uid = int_to_base36(user.id)
File "/home/person/testenv2/local/lib/python2.7/site-packages/django/utils/http.py", line 188, in int_to_base36
raise TypeError("Non-integer base36 conversion input.")

@brosner
Copy link
Member

brosner commented Jan 14, 2014

Depending on an integer primary key is going to cover 80% (most likely more than 80%) of the cases. I don't want to exclude the 20% entirely. I think the best way forward is to allow you to customize this behavior.

Do you have any suggestions on how you will handle encoding the ID data for future retrieval?

@apfejes
Copy link

apfejes commented Feb 4, 2014

I'd just like to add that I'm now being affected by this issue, using MongoDB/mongoengine with Django authentication.

I'm not sure what your question is asking, brosner. The ID data is coming from the primary key of the mongodb table, which is going to look like "_id" : ObjectId("52ec2cefb0e1464a8b37529a")

When Django gets this back, it's stripped of the ObjectId wrapper and becomes just "52ec2cefb0e1464a8b37529a", which is clearly not an int.

This bug is a showstopper for me, and I'm really not sure where to go from here.

@apfejes
Copy link

apfejes commented Feb 26, 2014

Figured I should follow up - in the end, I went back and installed all of the updated packages, and altered the libraries I was using, and thus managed to get it all working. If you get this error, you're probably doing "something wrong".

Key Settings for my project:

AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',)
SESSION_ENGINE = 'mongoengine.django.sessions'
SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'
TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.request',
)
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
     'django.contrib.admin',
     'django.contrib.admindocs',
)

and in views, I use:

 user.backend = 'django.contrib.auth.backends.ModelBackend'

If you need a working example, you can always check out my repository to see what I've done.

@ossanna16 ossanna16 changed the title assumption that user.id is an int, but this breaks when using django-nonrel Assumption that user.id is an int, but this breaks when using django-nonrel Dec 22, 2015
@brosner brosner modified the milestone: post-2.0.0 Oct 18, 2016
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

No branches or pull requests

3 participants