Opened 14 years ago
Closed 11 years ago
#15701 closed Bug (wontfix)
User._profile_cache cache collides when a model uses "profile" as related_name to User
Reported by: | David Gouldin | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | 1.2 |
Severity: | Normal | Keywords: | |
Cc: | dgouldin@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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()
Change History (9)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Summary: | User._cached_profile cache collides when a model uses "profile" as related_name to User → User._profile_cache cache collides when a model uses "profile" as related_name to User |
---|
comment:3 by , 14 years ago
Component: | Database layer (models, ORM) → Authentication |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 14 years ago
So is the solution to improve our error validation such that it checks for this name clash and forbids it?
comment:5 by , 14 years ago
Type: | → Bug |
---|
comment:6 by , 14 years ago
Severity: | → Normal |
---|
comment:9 by , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Marking as won't fix since AUTH_PROFILE_MODULE
is deprecated.
Note:
See TracTickets
for help on using tickets.
Whoops, title should obviously ready "User._profile_cache ...". Had it been named as the title suggests, the problem wouldn't have occurred. ;-)