Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#24516 closed Bug (invalid)

make_template_fragment_key behaves differently than the {% cache %} template tag for the "None" value

Reported by: Antonin Owned by: David Winterbottom
Component: Core (Cache system) Version: 1.7
Severity: Normal Keywords: cache, templatetag
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


The function make_template_fragment_key in django.core.cache.utils can be used to compute the cache key associated with a given template fragment.
When one of the parameters of this cache fragment get the value None, this function translates internally this value to 'None' (the string), whereas the template tag translates it to the empty string.

A patch for this bug can be found on the following branch:

Change History (6)

comment:1 Changed 5 years ago by Tim Graham

Needs tests: set
Triage Stage: UnreviewedAccepted

Could you please add a test and send a pull request? You may find the patch review checklist helpful.

comment:2 Changed 5 years ago by David Winterbottom

Owner: changed from nobody to David Winterbottom
Status: newassigned

comment:3 Changed 5 years ago by David Winterbottom

I can't recreate this sorry - I find that None gets passed to the make_template_fragment_key function when called from the template tag. Here's the snippet I used to test:

        from django.template import Context,Template
        t = Template(
            "{% load cache %}{% cache 300 test myvar %}hello{% endcache %}")
        t.render(Context({'myvar': None}))

What am I missing?

comment:4 Changed 5 years ago by David Winterbottom

Resolution: worksforme
Status: assignedclosed

comment:5 Changed 5 years ago by David Winterbottom

Have resolved for now but am happy to revisit if you can provide some info on how to recreate the issue.

comment:6 Changed 5 years ago by Tim Graham

Resolution: worksformeinvalid

Yes, the OP closed his PR has invalid, but forgot to close this ticket.

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