Page MenuHomeSoftware Heritage

api: Fix endpoint responses that must not be cached
ClosedPublic

Authored by anlambert on Nov 25 2020, 4:08 PM.

Details

Summary

Due to a recent factoring related to api_* decorators, the effect of
the never_cache django decorator was not applied anymore.

So add a never_cache parameter to the api_route decorator ensuring
cache-control reponse header will be set when required.

Also add missing tests checking cache-control header in api responses.

Closes T2810

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

douardda added a subscriber: douardda.

Thanks!
it's not completely clear why the @never_cache did not work any more, but meh.

This revision is now accepted and ready to land.Nov 25 2020, 4:14 PM

Build is green

Patch application report for D4595 (id=16311)

Rebasing onto 5351c2f85e...

Current branch diff-target is up to date.
Changes applied before test
commit 61236ca185a1e563c16db0824ec7049d52f7644b
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Nov 25 16:01:15 2020 +0100

    api: Fix endpoint responses that must not be cached
    
    Due to a recent factoring related to api_* decorators, the effect of
    the never_cache django decorator was not applied anymore.
    
    So add a never_cache parameter to the api_route decorator ensuring
    cache-control reponse header will be set when required.
    
    Also add missing tests checking cache-control header in api responses.
    
    Closes T2810

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/499/ for more details.

Build is green

Patch application report for D4595 (id=16312)

Rebasing onto 5351c2f85e...

Current branch diff-target is up to date.
Changes applied before test
commit 8492a4c688dba2c990ce6f50ecc754f08c1d740e
Author: Antoine Lambert <antoine.lambert@inria.fr>
Date:   Wed Nov 25 16:01:15 2020 +0100

    api: Fix endpoint responses that must not be cached
    
    Due to a recent factoring related to api_* decorators, the effect of
    the never_cache django decorator was not applied anymore.
    
    So add a never_cache parameter to the api_route decorator ensuring
    cache-control reponse header will be set when required.
    
    Also add missing tests checking cache-control header in api responses.
    
    Closes T2810

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/500/ for more details.

Thanks!
it's not completely clear why the @never_cache did not work any more, but meh.

Me neither, pile of decorators are hell. My guess is that the never_cache decorator must only be applied to the base view function and not a decorated one.
Anyway, I find it simpler this way and it enables to remove a couple of imports.

Thanks!
it's not completely clear why the @never_cache did not work any more, but meh.

Me neither, pile of decorators are hell. My guess is that the never_cache decorator must only be applied to the base view function and not a decorated one.
Anyway, I find it simpler this way and it enables to remove a couple of imports.

The @api_route decorator registers the inner function as a view in the django urls framework. AFAIK, the function returned by the @api_route decorator is never registered as a view anywhere, so it's, in effect, a dangling function that's never called. Decorating that function will not do anything.