﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15701	"User._profile_cache cache collides when a model uses ""profile"" as related_name to User"	David Gouldin	nobody	"Consider the following models in accounts/models.py

{{{
from django.contrib.auth.models import User
from django.db import models

class UserProfile(models.Model):
    user = models.OneToOneField(User, related_name=""real_profile"")

class NotUserProfile(models.Model):
    user = models.OneToOneField(User, related_name=""profile"")
}}}

With a setting in settings.py

{{{
AUTH_PROFILE_MODULE = 'accounts.UserProfile'
}}}

An orm call to User's manager with a select_related on ""profile"" will give the wrong answer for user.get_profile()

{{{
In [8]: user = User.objects.select_related('profile').all()[0]

In [9]: user.get_profile()
Out[9]: <NotUserProfile: NotUserProfile object>
}}}

This is due to a property name collision between User.get_profile

{{{
def get_profile(self):
    if not hasattr(self, '_profile_cache'):
        # ...
    return self._profile_cache
}}}

and RelatedObject

{{{
def get_cache_name(self):
    return ""_%s_cache"" % self.get_accessor_name()
}}}
"	Bug	closed	contrib.auth	1.2	Normal	wontfix		dgouldin@…	Accepted	0	0	0	0	0	0
