Code

Opened 2 years ago

Closed 2 years ago

#17643 closed Cleanup/optimization (fixed)

Misleading deprecation warnings raised by the cache_page decorator

Reported by: zsiciarz Owned by: zsiciarz
Component: Core (Other) Version: 1.4-alpha-1
Severity: Normal Keywords: deprecation
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The cache_page decorator should be called in The One True Way, which is:

@cache_page(120)
def my_view(request):
    # ...

Any old-style calls raise now a PendingDeprecationWarning. However, the warning that is printed to the stdout is misleading with regard to line numbers. All the warnings point to the warnings.warn call. It would be more useful to point to the actual @cache_page calls.

For the record, this is the current behaviour:

C:\Users\USER\v\django14\django\django\views\decorators\cache.py:47: PendingDeprecationWarning: The cache_page decorator must be called like: cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). All other ways are deprecated.
  PendingDeprecationWarning)
C:\Users\USER\v\django14\django\django\views\decorators\cache.py:47: PendingDeprecationWarning: The cache_page decorator must be called like: cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). All other ways are deprecated.
  PendingDeprecationWarning)
C:\Users\USER\v\django14\django\django\views\decorators\cache.py:47: PendingDeprecationWarning: The cache_page decorator must be called like: cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). All other ways are deprecated.
  PendingDeprecationWarning)
C:\Users\USER\v\django14\django\django\views\decorators\cache.py:47: PendingDeprecationWarning: The cache_page decorator must be called like: cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). All other ways are deprecated.
  PendingDeprecationWarning)

Attachments (1)

patch_17643.diff (696 bytes) - added by zsiciarz 2 years ago.
Setting correct stacklevel on the warnings.warn call.

Download all attachments as: .zip

Change History (5)

Changed 2 years ago by zsiciarz

Setting correct stacklevel on the warnings.warn call.

comment:1 Changed 2 years ago by zsiciarz

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 2 years ago by zsiciarz

With the patch applied:

C:\Users\USER\v\django14\django\tests\regressiontests\decorators\tests.py:133: PendingDeprecationWarning: The cache_page decorator must be called like: cache_page(timeout, [cache=cache name], [key_prefix=key prefix]).All other ways are deprecated.
  my_view_cached = cache_page(my_view, 123)
C:\Users\USER\v\django14\django\tests\regressiontests\decorators\tests.py:135: PendingDeprecationWarning: The cache_page decorator must be called like: cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). All other ways are deprecated.
  my_view_cached2 = cache_page(my_view, 123, key_prefix="test")
C:\Users\USER\v\django14\django\tests\regressiontests\decorators\tests.py:137: PendingDeprecationWarning: The cache_page decorator must be called like: cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). All other ways are deprecated.
  my_view_cached3 = cache_page(my_view)
C:\Users\USER\v\django14\django\tests\regressiontests\decorators\tests.py:139: PendingDeprecationWarning: The cache_page decorator must be called like: cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). All other ways are deprecated.
  my_view_cached4 = cache_page()(my_view)

comment:3 Changed 2 years ago by jezdez

  • Triage Stage changed from Unreviewed to Ready for checkin

comment:4 Changed 2 years ago by jezdez

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

In [17484]:

Fixed #17643 -- Set a better stack level for the cache_page decorator deprecation warnings. Thanks, zsiciarz.

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.