Opened 8 years ago

Closed 8 months ago

#17904 closed Bug (fixed)

Custom permissions on proxy model no longer created

Reported by: Koen Biermans Owned by: Arthur Rio
Component: contrib.auth Version: master
Severity: Normal Keywords: proxy contenttype permission
Cc: charette.s@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I have been using some specific permissions concerning the auth user model, so I created a proxy model on user like this:

class User(auth_models.User):
    class Meta:
        proxy = True
        permissions = (
            ("display_users", "May display users information"),
            ("edit_users", "May edit users information"),
        )

In 1.3 these custom permissions were created during syncdb (linked to the auth.User model).

Now I was testing my project with the 1.4 RC, and it turns out those permissions are no longer created.

This is caused by the refactor of the create_permissions code, which now uses get_for_models to determine the class to get the options for, but this returns the proxied class (auth.User), not the proxy class, so my custom permissions are not found and not created.

Attachments (1)

17904.diff (2.2 KB) - added by Claude Paroz 8 years ago.
Revert optimization of r16963

Download all attachments as: .zip

Change History (14)

comment:1 Changed 8 years ago by Ramiro Morales

Triage Stage: UnreviewedAccepted

The refactoring mentioned is r16963.

comment:2 Changed 8 years ago by Ramiro Morales

Version: 1.3SVN

Related tickets with pending conceptual/design decision: #11154, #17648 and #14492.

comment:3 Changed 8 years ago by Simon Charette

Cc: charette.s@… added

Actually the fix provided in #17648 would fix #11154 and this ticket, #14492 is really about another issue.

Changed 8 years ago by Claude Paroz

Attachment: 17904.diff added

Revert optimization of r16963

comment:4 Changed 8 years ago by Claude Paroz

Has patch: set

Unless #17648 is fixed (proxy models having their own distinct ContentType) and we are probably too late in the 1.4 cycle for such a change, reverting the optimization of r16963 is probably the safest move at this time.

comment:5 Changed 8 years ago by Aymeric Augustin

In [17776]:

Reverted parts of r16963 to fix a regression on the creation of permissions on proxy models. Refs #17904. Thanks koenb for the report and claudep for the patch.

comment:6 Changed 8 years ago by Aymeric Augustin

Has patch: unset
Severity: Release blockerNormal

I'm leaving this ticket open so we remember to reactivate this optimization, once the situation with proxy models is improved.

comment:7 Changed 7 years ago by Simon Charette

Has patch: set
Keywords: proxy contenttype permission added

Now that #18399 is fixed, I created a pull request that brings back the get_for_models permission creation optimization while passing the test added in r17776. Note that this patch fixes #11154 at the same time so it includes an extra test.

comment:8 Changed 6 years ago by Tim Graham

Needs documentation: set

Pull request was closed indicating this needs docs.

comment:9 Changed 4 years ago by Tim Graham

A newer pull request was closed as the submitter couldn't address the security concerns raised there. Someone else is welcome to follow up and try to address them.

comment:10 Changed 12 months ago by Arthur Rio

Owner: changed from nobody to Arthur Rio
Status: newassigned

I'm going to try to address the security concerns in a new pull request.

comment:11 Changed 12 months ago by Arthur Rio

Needs documentation: unset

comment:12 Changed 12 months ago by Carlton Gibson

Patch needs improvement: set

comment:13 Changed 8 months ago by Tim Graham

Resolution: fixed
Status: assignedclosed

This ticket is fixed but it was kept open to restore the optimization of f04af7080b12744c8f06fb8228ef683d556690d0 (using ContentType.objects.get_for_models()). PR 10381 doesn't restore the optimization although it's been linked to this ticket. I tried using get_for_models() in that patch, but it doesn't work anymore because create_permissions() now uses model states (which don't have custom methods). Here's the error:

  File "/home/tim/code/django/django/contrib/contenttypes/models.py", line 89, in get_for_models
    opts_models = needed_opts.pop(ct.model_class()._meta, [])
AttributeError: 'ContentType' object has no attribute 'model_class'

If someone wants to look at that optimization again, please open a new ticket.

Note: See TracTickets for help on using tickets.
Back to Top