Opened 13 years ago

Closed 13 years ago

#17643 closed Cleanup/optimization (fixed)

Misleading deprecation warnings raised by the cache_page decorator

Reported by: Zbigniew Siciarz Owned by: Zbigniew Siciarz
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 Zbigniew Siciarz 13 years ago.
Setting correct stacklevel on the warnings.warn call.

Download all attachments as: .zip

Change History (5)

by Zbigniew Siciarz, 13 years ago

Attachment: patch_17643.diff added

Setting correct stacklevel on the warnings.warn call.

comment:1 by Zbigniew Siciarz, 13 years ago

Has patch: set

comment:2 by Zbigniew Siciarz, 13 years ago

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 by Jannis Leidel, 13 years ago

Triage Stage: UnreviewedReady for checkin

comment:4 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [17484]:

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

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