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

assign_perm doesn't work in migrations (Django 1.8, Guardian 1.3) #333

Closed
keattang opened this issue Jul 15, 2015 · 1 comment
Closed

assign_perm doesn't work in migrations (Django 1.8, Guardian 1.3) #333

keattang opened this issue Jul 15, 2015 · 1 comment

Comments

@keattang
Copy link
Contributor

I'm trying to run a migration that looks like this:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from guardian.shortcuts import assign_perm, get_objects_for_user
from django.contrib.auth import get_user_model


def setUserPerms(apps, schema_editor):
    User = get_user_model()
    Project = apps.get_model('api', 'Project')

    for proj in Project.objects.all():
        print("Setting owner permissions for "+proj.name+"//"+user.username)
        user = User.objects.get(pk=proj.owner_user.pk)
        assign_perm('manage_project', user, proj)

class Migration(migrations.Migration):

    dependencies = [
        ('api', '0077_auto_20150715_0504'),
    ]

    operations = [
        migrations.RunPython(setUserPerms, reverse_code=migrations.RunPython.noop),
    ]

The migration runs without any errors and successfully prints to the terminal but upon inspecting the database no changes are actually made and the permissions therefore not set.

@brianmay
Copy link
Contributor

I am going to close this and use #281 instead, as most of the discussion is already there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants