Instead of get_permission('app_label.permission_name'), why not punt on the 
problem
until schema migrations lands. Only provide a plural helper method that 
always returns 
a list. The first argument could be either a string or a list of strings. 
This leaves it up to
the caller to determine what to do if more than one is returned when they 
only expected
a single result. Having all of the conflicts is a lot more useful than the 
"returned more than
1" exception.

Regards,
Michael Manfre

On Wednesday, September 19, 2012 6:41:25 PM UTC-4, Anssi Kääriäinen wrote:
>
> We use the style of "app_label.permission_name" in multiple places of 
> our code to refer to given auth.models.Permission. However, there is 
> no unique key for that combination, the key is content_type, 
> permission_name. I verified that it is actually possible to hit this 
> problem by using the Meta.permissions. 
>
> I am not sure what we can do about this... Or if we even need to do 
> anything about this. 
>
> Without schema changes we can't have a DB constraint for the key. But, 
> maybe we could validate (as part of model validation) that there are 
> no overlapping permissions? If the user goes and creates overlapping 
> permissions despite of this, we can't do anything about that. 
>
> The reason why I am wondering about this is that I'd like to add 
> Permissions.objects.get_permission('app_label.permission_name') 
> convenience method. And, while investigating that I realized that the 
> app_label, permission name isn't a key... 
>
> I am likely going to add the get_permission() anyways, it will just 
> throw "returned more than 1" if the above problem is hit. 
>
> Thoughts? 
>
>  - Anssi 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/_ool0iQ7kKwJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to