Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for implication of renaming a model for resource registry / RBAC #227

Open
AlanCoding opened this issue Mar 18, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@AlanCoding
Copy link
Member

Consider renaming a model, Cow in test_app to Cow2. After doing that experimentally locally and migrating:

from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission

ContentType.objects.filter(model__icontains='cow')
Permission.objects.filter(content_type__model__icontains='cow')

After migration, you will find that ContentType handles this gracefully. The Django Permission class does not:

In [4]: list(Permission.objects.filter(content_type__model__icontains='cow').values_list('codename', flat=True))
Out[4]: 
['add_cow',
 'add_cow2',
 'change_cow',
 'change_cow2',
 'delete_cow',
 'delete_cow2',
 'say_cow',
 'view_cow',
 'view_cow2']
In [10]: Permission.objects.filter(content_type__model__icontains='cow')[2].codename
Out[10]: 'change_cow'

In [11]: Permission.objects.filter(content_type__model__icontains='cow')[2].content_type
Out[11]: <ContentType: test_app | cow2>

The old permissions reference the new model but keep the old entries.

Given that this is unsolved in the standard permission model, I think it is a bad idea to embark on on fix in this project (you should fix it in Django itself first). So this should be handled by documenting the behavior and what is needed to work around.

@AlanCoding AlanCoding changed the title Document for implication of renaming a model for resource registry / RBAC Documentation for implication of renaming a model for resource registry / RBAC Mar 19, 2024
@AlanCoding AlanCoding added the documentation Improvements or additions to documentation label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant