scholrly / neo4django

Drop-in Neo4j/Django integration.
GNU General Public License v3.0
358 stars 83 forks source link

Add an adapter so Django stores the right value #154

Closed bhcarpenter closed 11 years ago

bhcarpenter commented 11 years ago

Add an adapter so Django stores the right value into session. We want to store and use the user_id property instead of the id.

Retrieving the User via user_id was already taken care of. This takes care of storing the user_id.

Refs #152

mhluongo commented 11 years ago

I'm a little concerned because of some edge cases like querying- eg User.objects.get(id=5). The resulting object will have act like this

>>> user = User.objects.get(id=5)
>>> user.id
5
>>> user.user_id
# some other id
>>> user.id == user.user_id
False

OTOH,

>>> user = login(...)
>>> user.id
# some other id
>>> user.id == user.user_id
True

Obviously this particular example is easy to test so I'll get on that.

I'm going to leave this open and see if I can get primary_key=True working properly (and really just explore further)- if there's still a problem we might have to do this or something similar.

bhcarpenter commented 11 years ago

Yep that's exactly right (and even intended).

Unfortunately, django.contrib.auth persists the id field of the user given to login, so if we want to have get_user retrieve by user_id instead later, we'll have to fake it somehow.

I agree that this is probably going to cause issues (and I already know that it breaks django_social_auth). Let's keep talking offline.