Opened 10 years ago

Closed 10 years ago

#23750 closed Cleanup/optimization (fixed)

django.core.checks.register shouldn't be (primarily) a decorator

Reported by: Shai Berger Owned by: averybigant
Component: Core (System checks) Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

django.core.checks.register is commonly used as a function, called from AppConfig.ready(), and not as a
decorator; but it is defined as a decorator, so it looks a little funny:

        checks.register('models')(check_generic_foreign_keys)

(from the contenttypes AppConfig, for example).

Registering checks only in ready(), rather than at import time, is now the way
to do things, so register() should typically not be used as a decorator; I
think we should change its definition accordingly, to

        def register(self, check, *tags)

The above is, essentially, an old message of mine to django-developers; in that thread, you can find Russell agreeing, and Marc adding that the checks documentation needs to change as well. However, since 1.7 was already released, register needs to be changed in a backwards-compatible way -- so that it can be used either as it is currently, or using the more natural style.

Change History (5)

comment:1 by averybigant, 10 years ago

Owner: changed from nobody to averybigant
Status: newassigned

comment:2 by averybigant, 10 years ago

Has patch: set
Needs tests: unset

comment:3 by Tim Graham, 10 years ago

Patch needs improvement: set

I left comments for improvement on the PR. Please uncheck "Patch needs improvement" when you update it, thanks.

in reply to:  3 comment:4 by averybigant, 10 years ago

Patch needs improvement: unset

Replying to timgraham:

I left comments for improvement on the PR. Please uncheck "Patch needs improvement" when you update it, thanks.

new commit pushed.

comment:5 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In b7a5b6ab8672daf907ba57e50edbed4cad596d4b:

Fixed #23750 -- Allowed core.checks.register to be used as a function

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