[Django] #32695: Create Permissions with create() instead of bulk_create() to send signal

34 views
Skip to first unread message

Django

unread,
Apr 28, 2021, 5:13:39 PM4/28/21
to django-...@googlegroups.com
#32695: Create Permissions with create() instead of bulk_create() to send signal
------------------------------------------------+------------------------
Reporter: laurent-brisbois | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.auth | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+------------------------
Hello there !

It seems Django is creating new Permission records in a post_migrate
signal handler, especially in the method create_permissions which is
called
[https://github.com/django/django/blob/263ee4434fe814ee15ef231549273f16d7fad520/django/contrib/auth/apps.py#L20
here].

It would be great if it was possible to act on Permission creation. I mean
by using create() instead of bulk_create(), pre_save() and post_save()
signals would be sent and therefore it would be possible to, for instance,
assign a Permission once it is created with the post_save() signal.

I guess the only think to do would be to change
[https://github.com/django/django/blob/263ee4434fe814ee15ef231549273f16d7fad520/django/contrib/auth/management/__init__.py#L83
this line].

I could even do it if you say it will be accepted.

Otherwise how could it be possible to achieve it ? I mean assign a
Permission once it is created..?

Kind regards,

A Django Lover.

--
Ticket URL: <https://code.djangoproject.com/ticket/32695>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 28, 2021, 6:25:30 PM4/28/21
to django-...@googlegroups.com
#32695: Create Permissions with create() instead of bulk_create() to send signal
-------------------------------------+-------------------------------------
Reporter: BRISBOIS Laurent | Owner: BRISBOIS
Type: | Laurent
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by BRISBOIS Laurent):

* owner: nobody => BRISBOIS Laurent
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32695#comment:1>

Django

unread,
Apr 28, 2021, 6:46:44 PM4/28/21
to django-...@googlegroups.com
#32695: Create Permissions with create() instead of bulk_create() to send signal
-------------------------------------+-------------------------------------
Reporter: BRISBOIS Laurent | Owner: BRISBOIS
Type: | Laurent
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by BRISBOIS Laurent):

Added a PR to solve this : https://github.com/django/django/pull/14326

--
Ticket URL: <https://code.djangoproject.com/ticket/32695#comment:2>

Django

unread,
Apr 28, 2021, 9:00:06 PM4/28/21
to django-...@googlegroups.com
#32695: Create Permissions with create() instead of bulk_create() to send signal
-------------------------------------+-------------------------------------
Reporter: BRISBOIS Laurent | Owner: BRISBOIS
Type: | Laurent
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Permission creation was changed from `create()` to `bulk_create()` in
7deb25b8dd5aa1ed02b5e30cbc67cd1fb0c3d6e6 (#7596).

--
Ticket URL: <https://code.djangoproject.com/ticket/32695#comment:3>

Django

unread,
Apr 28, 2021, 9:23:01 PM4/28/21
to django-...@googlegroups.com
#32695: Create Permissions with create() instead of bulk_create() to send signal
-------------------------------------+-------------------------------------
Reporter: BRISBOIS Laurent | Owner: BRISBOIS
Type: | Laurent
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by BRISBOIS Laurent):

I see that it seems to be only a performance reason that was behind this
original change.
But what if people need to react on this (in my opinion) important step
which is the creation of the Permissions ?

I think it should be considered again to put `create()` back here

--
Ticket URL: <https://code.djangoproject.com/ticket/32695#comment:4>

Django

unread,
Apr 29, 2021, 8:04:29 PM4/29/21
to django-...@googlegroups.com
#32695: Create Permissions with create() instead of bulk_create() to send signal
-------------------------------------+-------------------------------------
Reporter: BRISBOIS Laurent | Owner: BRISBOIS
Type: | Laurent
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by BRISBOIS Laurent):

* has_patch: 0 => 1
* stage: Unreviewed => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32695#comment:5>

Django

unread,
Apr 29, 2021, 8:11:26 PM4/29/21
to django-...@googlegroups.com
#32695: Create Permissions with create() instead of bulk_create() to send signal
-------------------------------------+-------------------------------------
Reporter: BRISBOIS Laurent | Owner: BRISBOIS
Type: | Laurent
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Ready for checkin => Unreviewed


Comment:

Please don't mark your own ticket and patch as ready for checkin. The
ticket should be triaged and the patch reviewed by another person.

--
Ticket URL: <https://code.djangoproject.com/ticket/32695#comment:6>

Django

unread,
Apr 30, 2021, 4:30:04 AM4/30/21
to django-...@googlegroups.com
#32695: Create Permissions with create() instead of bulk_create() to send signal
-------------------------------------+-------------------------------------
Reporter: BRISBOIS Laurent | Owner: BRISBOIS
Type: | Laurent
Cleanup/optimization | Status: assigned
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by BRISBOIS Laurent):

@Tim Graham Huh sorry I read
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/submitting-patches/#patch-review-checklist this] and I may have made a
mistake. My apologies. I didn't intend to force it at all.

--
Ticket URL: <https://code.djangoproject.com/ticket/32695#comment:7>

Django

unread,
Apr 30, 2021, 4:46:22 AM4/30/21
to django-...@googlegroups.com
#32695: Create Permissions with create() instead of bulk_create() to send signal
-------------------------------------+-------------------------------------
Reporter: BRISBOIS Laurent | Owner: BRISBOIS
Type: | Laurent
Cleanup/optimization | Status: closed
Component: contrib.auth | Version: 3.2
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* resolution: => wontfix


Comment:

> But what if people need to react on this (in my opinion) important step
which is the creation of the Permissions?

I think it's really niche because no one has reported this in the last 10
years. You should be able to add e.g. a `post_migrate` handler or a
scheduler job and check for new permissions. You can also try to ask for
alternatives on one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels]. I don't think this is worth changing at the moment.

Moreover, as far as I'm aware your issue will be fixed by #29843, which
propose including permissions in migrations files.

--
Ticket URL: <https://code.djangoproject.com/ticket/32695#comment:8>

Reply all
Reply to author
Forward
0 new messages