﻿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
7203	Admin error if an edit_inline=True object has a ForeignKey to some other object which has a unique_together specification	Scott Moonen <smoonen@…>	nobody	"Here's a reduced example:

{{{
class Organization(models.Model) :
  pass

class User(models.Model) :
  organization = models.ForeignKey(Organization)
  username = models.SlugField(max_length = 30)
  class Meta :
    unique_together = ('organization', 'username')

class OrganizationService :
  organization = models.ForeignKey(Organization)
  service = models.SlugField(max_length = 30)
  class Meta :
    unique_together = ('organization', 'service')

class ServiceUser :
  user = models.ForeignKey(User, edit_inline = models.TABULAR)
  organization_service = models.ForeignKey(OrganizationService)
  class Meta :
    unique_together = ('organization_service', 'user')
}}}

So, !ServiceUser is related to User and is edited inline there.  !ServiceUser is also related to !OrganizationService.  So, when we go to edit User in the admin interface, it builds the following get_follow list:

{{{
{'username': True, 'myapp:serviceuser': {'organization_service': True, 'id': True, 'user': False}, 'organization': True, 'id': True}
}}}

The problem is that the inner dictionary has 'organization_service' set to True.  This results in our trying to extend the User !ChangeManipulator with the unique_together validator for !OrganizationService.  That fails:

{{{
AttributeError at /myapp/user/6/
'ChangeManipulator' object has no attribute 'isUniqueorganization_service_user'
}}}

The 'organization_service' follow indicator is set to True because !RelatedObject.get_follow is smart enough to force the edit_inline !ForeignKey to have False for follow, however it doesn't set follow for other !ForeignKey relations in the edit_inline object to False:

'''over[self.field.name] = False'''

I'm not sure what the right way is to fix this.  I almost think that Options.get_follow needs a new parameter to indicate whether all !ForeignKey relationships (not only the one that has edit_inline set) should be forced to False.  Or, alternatively, we could create an alternative function to Options.get_follow with this behavior.  We can then force this behavior in the call from !RelatedObject.get_follow, but keep the existing behavior in the call from !AutomaticManipulator.  I'm not sure if that would create broader problems, though.

This bug is a little more problematic than average, since I can't find an easy workaround apart from removing the edit_inline = True specification."		closed	Database layer (models, ORM)	dev		fixed			Unreviewed	0	0	0	0	0	0
