Code

Opened 3 years ago

Closed 3 years ago

#15604 closed (fixed)

django.db.models.permalink eats docstring

Reported by: sfllaw Owned by: nobody
Component: Core (Other) Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The django.db.models.permalink decorator eats docstrings, along with the other metadata that it is wrapping. That's because it's not using functools.wraps on its inner function.

It should be defined like this:

from django.utils.decorators import wraps

def permalink(func):
    from django.core.urlresolvers import reverse
    @wraps
    def inner(*args, **kwargs):
        bits = func(*args, **kwargs)
        return reverse(bits[0], None, *bits[1:3])
    return inner

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by sfllaw

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Whoops, that wraps line should be:

@wraps(func)

comment:2 Changed 3 years ago by adrian

  • Triage Stage changed from Unreviewed to Accepted

Good improvement. I'll add this along with some tests.

comment:3 Changed 3 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

In [15798]:

Fixed #15604 -- Changed django.db.models.permalink to use wraps() so that it doesn't eat the docstring. Thanks for the report, sfllaw. Also added tests.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.